Next.js App API route returning 404 even though route is present

Summary

I have a POST:/api/github route in my next.js app.
Path to file: src/app/api/github/route.ts

When I try calling the API from postman, it returns 404 error, when I open up browser to just check in case, that also returns 404 error. I also don’t have any conflicting paths in app router

PFA the screenshots for more details:

Directory ss:

Ngrok API Response ss:
image

Next.js logs:
image

Code SS:

Please help. Thanks!

Additional information

"next": "15.1.2",
"react": "^19.0.0",

middleware.ts code:


export const config: MiddlewareConfig = {
  matcher: [
    "/login",
    "/logout",
    "/api/:path*",
    "/dashboard/:path*",
    "/user/:path*",
  ],
};

There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.

A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0.

I noticed something, so when I have some logic inside my route handler, it goes 404, but when I do something like:

import type { NextApiRequest } from 'next';

export async function POST(
  req: NextApiRequest,
) {
  return Response.json({ message: 'Hello from Next.js!' })
}

Then it works fine. Not sure what this behaviour is though.