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

256
Visualizações
Nextjs SSR fetch origin

Using the Nextjs getServerSideProps function I make a fetch request to my API. My API checks origin headers for CORS but gets the origin header as undefined. Why is this happening and is there a way around this?

I get origin headers while making fetch requests normally from the browser in Next. This issue only occurs when the request is made to the API via the server from Nextjs getServerSideProps.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What I did was adding the Origin parameter to the header object in the fetch request and adding the url from the .env file to easily change it for production.

  //Create fetch's options
  const options = {
     mode: 'cors',
     method: 'GET',
     credentials: 'include',
     headers: {
        'Content-Type': 'application/json',
        Origin: `${process.env.NEXT_PUBLIC_FRONT_URL}`,
     },
  };

  //Fetch data from the API
  const res = await fetch('changeForYouURL', options);
about 4 years ago · Juan Pablo Isaza Relatório
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