Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda