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

289
Visualizações
Next.js API routes all return "Interval Server Error" in production, but all the routes work in development

Whenever I go to any API route in my Next.js app in production it returns a 500 "Internal Server Error" but in development, all of them work completely fine and show/return what I expect them to.

another example of the error

the error

I am deploying with an AWS Ec2 instance.

the code is available here: https://github.com/123om123/NFT-Marketplace

These are all my API routes.

enter image description here

The [...auth0].js creates the following routes: /api/auth/login, /api/auth/logout, /api/auth/callback, and /api/auth/me

If I try to access the "find_account" API route like the following:

  let findAccount = async function () {
    await fetch("/api/find_account", {
      method: "POST",
      body: JSON.stringify({
        DBUrl: DBUrl,
        user_id: user.sub,
      }),
    })
      .then(async (response) => {
        await response.json().then((result) => {
          accountData = result;
          if (accountData.data.allAccounts.nodes[0].addresses !== null) {
            setAddressList(accountData.data.allAccounts.nodes[0].addresses[0].split(","));
          }
        });
      })
      .catch((err) => {
        return err;
      });
  };

which handles requests like the following:

export default function handler(req, res) {
  req.body = JSON.parse(req.body);
  fetch(req.body.DBUrl, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      query: `query MyQuery {
        allAccounts(condition: {userId:"${req.body.user_id}"}) {
          nodes {
            addresses
          }
        }
      }`,
    }),
  })
    .then((response) => {
      response.json().then((response) => {
        res.status(200).send(response);
      });
    })
    .catch((err) => {
      res.status(500).send(err);
    });
}

it works fine and returns the response from the graphql API in development, but in production it shows the above error.

The problem seems to be that the API routes aren't even created and are therefore inaccessible. All the API routes worked a few weeks ago, but now they seem to have stopped working.

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

0

Check out this answer, it helped me solve a bug similar to yours. In my case when vercel was deploying my PR branch I was getting a 500 Internal Error. Once I merge the PR into main and vercel does a fresh deployment, I was now getting a 504 gateway error. The answer below helped me find out why.

https://stackoverflow.com/a/68774331/12775824

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