Next.js Discord

Discord Forum

NextJS 15 Basic API Route Always Returning 404

Answered
Billy posted this in #help-forum
Open in Discord
Avatar
BillyOP
Anyone else having issues getting a really basic API request working in NextJS 15? I have a request /api/revalidate with
import { revalidateTag } from 'next/cache'
import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'

export async function GET(): Promise<any> {
  // revalidateTag('services.update')
  return NextResponse.json({ hello: 'hi' })
}

and when I make a request it returns a 404. I know in theory the force-dynamic isn't needed anymore as they fixed it but it made no difference without it
Answered by Jboncz
look at your route..ts file
View full answer

50 Replies

Avatar
BillyOP
@Jboncz 🙂
Avatar
What nextjs version you running?
Avatar
BillyOP
latest stable
Avatar
so 15. okay I havent done anything with it yet. give me one sec.
Avatar
BillyOP
👍
Avatar
ill bootstrap a new proj rq
What does the path to that route.js file look like?
This works no issues.
Image
Avatar
BillyOP
/src/app/api/revalidate/route.ts
Avatar
in your browser your hitting localhost:3000/api/revalidate yeah?
Avatar
BillyOP
browser and Postman
Avatar
Hrmmm.
I have zero issues.
Image
with TS
import { NextResponse } from "next/server";



export async function GET(request: Request) {
    return NextResponse.json({hello: 'hi'})
}


Can you try replacing your code with this and see if it works
Avatar
BillyOP
Image
Avatar
can you confirm that you can get to localhost:3000?
just the base route?
Avatar
BillyOP
Everything else works
Avatar
are you in build or dev?
Avatar
BillyOP
dev
Iv tried turbo and non turo
turbo*
Avatar
Can you show me your output in the terminal?
Image
Avatar
BillyOP
Image
Avatar
can you send me a screenshot of your file directory leading to the route.js file?
Image
Avatar
BillyOP
The errors is just the formatting and missing types, as I directly copied and pasted your code.
Image
Avatar
Sorry for asking basic questions... just never know.
Avatar
BillyOP
wait a fkn sec
Avatar
You find something?
..ts
LMAO
gottem
Avatar
BillyOP
nvm
Avatar
look at your route..ts file
Answer
Avatar
BillyOP
:sad:
Avatar
remove a period and I think thatll do it for ya
Avatar
BillyOP
its 6AM and iv been up since 8AM yesterday
how tf didn't I see that
Avatar
Hahah, all good man.
Avatar
BillyOP
I feel stupid
Avatar
Thats why I was asking for screenshots it happens.
No worries!
Avatar
BillyOP
Well thanks for the help.
❤️
Avatar
np. please mark an answer using the replied to chat.
Just so it closes and indexs and all that jazz
GL!
and ty for closing