Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
nuxt app deployed to Netlify: fetch to api working locally, but not on deployed site: getting a 404

I have a Nuxt.js app that I'm trying to deploy to Netlify - and everything works on my local machine, but the fetch request to the api returns a 404 when it's deployed to Netlify. I don't know how to make that server route available to my client when it's deployed.

the fetch request in my api-client.js file looks like this:

 async fetchInfo(state) {
    let response = await fetch(`/api/info/${state}`);
      let data = await response.json();
      return data;
  } 

and the api looks like this (in api/index.js file):

const rp = require('request-promise');
const apiKey = process.env.POLICY_API_KEY;

export default function (req, res, next) {
  if (req.url.includes("/info")) {
    let stateAbbr = req.originalUrl.slice(-2);
    rp({
      uri: `https://third-party-api-here.com/states/${stateAbbr}/`,
      method: 'GET',
      headers: { 
        'token': apiKey,
      },
      json: true
    }).then(function success(response) {
        if (response) {
          res.setHeader('Content-Type', 'application/json');
          res.end(JSON.stringify(response));
          return;
        }
    }).catch(function error(response) {
        console.log('error', response.error);
    });
    return;
  }
  next();
}

I think this might have something to do with CORS? I'm getting this error in the browser when I try to hit that route in the deployed app: GET https://my-app-name.netlify.app/api/info/MN 404 SyntaxError: Unexpected token < in JSON at position 0

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda