Even Simple Next.js API timeout on Vercel

179 views Asked by At

Every API in the NextJS project is giving a 504 bad gateway time out error only in vercel production deployment, everything works fine in local, so I added a hello GET API with the sample code.

export default function handler(req, res) {
  res.status(200).json({ message: 'Hello from Next.js!' })
}

but this does fail too with 504

504: GATEWAY_TIMEOUT Code: FUNCTION_INVOCATION_TIMEOUT

this is the link.

When I checked the vercel log the API sometimes rarely works for once and then starts to fail with 504 again.

My code is located at src\pages\api in the root

1

There are 1 answers

3
grekier On

This is because the URL is "wrong". You use https://glomium-dashboard.vercel.app/api/hello/ but this file would be at https://glomium-dashboard.vercel.app/api/hello (without forward slash at the end) and is working nicely.

The URL you are trying to reach (with forward slash at the end) would map to an index file under src/pages/api/hello/ or should redirect to URL without slash. I guess you might have a conflicting URL somewhere.