Next.js All API routes return 404 while working fine locally

Hello, I’m using Next.js 14.2.3 with the app router, and I decided to add an API to my project. It worked fine locally, but when I deployed it to Vercel, it returned the default Next.js 404 page.

I created the API route at src/api/test/route.ts with the following code for testing:

export const dynamic = 'force-dynamic'; 
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
    return NextResponse.json({ message: "Test" }, { status: 200 })
}

Current versus Expected Behavior

  • Current Behavior: The API route returns a 404 error on Vercel.
  • Expected Behavior: The API route should return a JSON response with the message “Test”.

Hi, @itsjokerdev! Welcome to the Vercel Community :smile:

It would be helpful to see a minimal reproducible example - could you share one with us?

Thank you :pray:

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