Unable to reach my API endpoints
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
Hello folks this is my tree:
Is my middleware the reason?
Is my (public) folder the reason?
app/
├── (public)
│  ├── [user]
│  │  └── page.tsx
│  ├── customers
│  │  ├── [slug]
│  │  │  └── page.tsx
│  │  └── page.tsx
│  ├── layout.tsx
│  ├── legal
│  │  └── [slug]
│  │  └── page.tsx
│  ├── page.tsx
│  └── pricing
│  └── page.tsx
├── api
│  └── places
│  ├── [id]
│  │  └── route.ts
│  └── route.ts
├── auth
│  ├── callback
│  │  └── route.ts
│  └── page.tsx
├── dashboard
│  ├── branches
│  │  ├── [id]
│  │  │  └── page.tsx
│  │  ├── new
│  │  │  └── page.tsx
│  │  └── page.tsx
│  ├── layout.tsx
│  ├── page.tsx
│  └── settings
│  └── page.tsx
├── globals.css
├── layout.tsx
├── middleware.ts
├── robots.ts
└── sitemap.ts
18 directories, 22 files
Is my middleware the reason?
Is my (public) folder the reason?
25 Replies
Brown bearOP
Next responses me with 404 page / error
Asian black bear
Share the code of one of the endpoints that yields a 404
Brown bearOP
import { NextResponse } from "next/server";
export const GET = async (request: Request) => {
return NextResponse.json({
message: "Hello from places",
});
};
😂
So simply
I've removed my next folder, pnpm dev again and same shit
Asian black bear
And what does your middleware look like?
Brown bearOP
import { createMiddlewareSupabaseClient } from "@supabase/auth-helpers-nextjs";
import { type NextRequest, NextResponse } from "next/server";
// import type { Database } from '@/lib/database.types'
export async function middleware(req: NextRequest) {
const res = NextResponse.next();
const supabase = createMiddlewareSupabaseClient({ req, res });
await supabase.auth.getSession();
return res;
}
Using supabase btw
Asian black bear
Then remove it first to see whether the API endpoint is reachable without Middleware
Brown bearOP
hold on
Same shit
😦
Asian black bear
How are you attempting to access the API? Via Postman, curl or in code using fetch?
Brown bearOP
By the browser, but even using httpie for example dont work
Asian black bear
So
http://localhost:3000/api/places
and http://localhost:3000/api/places/foo
both return 404?Brown bearOP
yeah
both
Asian black bear
Did you configure some base URL or something similar?
Brown bearOP
crazy man 🤯
on my next.config? Nope
Asian black bear
Then start bisecting the code. Deleting half the code until it works
And figuring out what causes the issue.
Gut feeling is that maybe routing has a conflict.
Brown bearOP
Oh shit jaja 😦