Issue on API endpoint
Answered
Mudi posted this in #help-forum
MudiOP
Hello, I got my /app/api/test/route.ts and http://localhost:3000/api/test works OK but then I'm trying to make another route on /app/api/hello/route.ts and it doesn't work "404
This page could not be found." & I'm even using an example code from the website
This page could not be found." & I'm even using an example code from the website
25 Replies
Are you exporting the handler the right way?
export async function GET(){
return NextResponse.json("Hello World!");
import { headers } from 'next/headers'
export async function GET(request: Request) {
const headersList = await headers()
const referer = headersList.get('referer')
return new Response('Hello, Next.js!', {
status: 200,
headers: { referer: referer || '' },
})
}
This is my code
Well that's weird ... if the handler is Ok and your folder structure is Ok (is it?) what I would do is deleting the
.next
folder and run the app again.Stills doesn't work
I get GET /api/hello 404 in 89ms
this is my structure
You have double .
In the /api/hello/route.ts you have route..ts
In the /api/hello/route.ts you have route..ts
Answer
MudiOP
🤦🏿♂️
Thanks dude
Sorry for wasting your time
No don’t worry, for the record, deleting the .next folder sometimes work for weird issues lol.
MudiOP
I see lol
I was never going to get this
Didn't see double dot
😂
@LuisLl Well that's weird ... if the handler is Ok and your folder structure is Ok (is it?) what I would do is deleting the `.next` folder and run the app again.
That’s why I said “(is it?)” lol sometimes the folder structure is the whole problem
You’re good 🤣
MudiOP
hahaha
thank you
have nice day

You too!
Before you leave mark the solution!
Before you leave mark the solution!