Next.js Discord

Discord Forum

Route handler 404

Unanswered
Sloth bear posted this in #help-forum
Open in Discord
Sloth bearOP
I have API Route:
src/app/api/commercetools/[...slug].tsx

With
export async function GET(request: NextRequest) {
console.log('handleRequestHit')
// Response 200..
}

Why does this still return 404?
https://localhost:3001/api/commercetools/category/7d832834-7666-4053-9d2d-10daaaf7db91

3 Replies

Sloth bearOP
Okay so, this works:
src/app/api/commercetools/category/[slug]/route.tsx
With URL:
https://localhost:3001/api/commercetools/category/7d832834-7666-4053-9d2d-10daaaf7db91

That makes sense. But I will have a lot of endpoints like:
https://localhost:3001/api/commercetools/products/7d832834-7666-4053-9d2d-10daaaf7db91
https://localhost:3001/api/commercetools/items/7d832834-7666-4053-9d2d-10daaaf7db91

So I want one single proxy file without creating a subfolder for each.
you can create a route like this src/app/api/commercetools/[category]/[slug]/route.tsx if you dont want to create multiple folder
you can also use your example of catchall but make sure to include the route.tsx, but Ray's solution is best if you know its only 2 (better typing and such)