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-Marketplaceblackshow
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.

Hey there @georgemendellextra, welcome to the community!

Were you ever able to get this sorted? It’s really difficult to know for sure, but the fact that everything functions as expected before deployed to AWS makes me think the issue is there. I haven’t seen this specific behavior, but similar development vs. prod issues in the past have almost always been related to a config in AWS. Is there any more information available on the 500 error?

Let us know!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.