Next.js Discord

Discord Forum

accessing route handler issues 404 error

Unanswered
Champagne D’Argent posted this in #help-forum
Open in Discord
Champagne D’ArgentOP
I have this route handler at src/app/api/foo/route.ts:
export async function GET(_request: Request) {
  return Response.json({ sup: "yo" });
}

but going to http://localhost:3000/api/foo issues this error:
404: NOT_FOUND
Code: NOT_FOUND
ID: dev1::1q4p8-1697936493642-3afd6458a45a

when running vercel dev but is ok if I run npm run dev. Does this mean that I have to choose between the vercel serverless functions at /api/... and the nextjs routes? how to fix this?

6 Replies

@Champagne D’Argent try something like postman to do a get request
well... vercel explicitly says to not use the vercel cli to test when using nextjs... (deploying is different)
If you're using a framework and your framework's Development Command already provides all the features you need, we do not recommend using vercel dev.

For example, Next.js's Development Command (next dev) provides native support for Functions, redirects, rewrites, headers and more.
https://vercel.com/docs/cli/dev#when-to-use-this-command
well technically you can have some vercel.json spaghetti to get both to work at the same time, but i can't find it and i wouldn't say that is a maintainable setup