Unable to reach my API endpoints
Unanswered
Brown bear posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
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
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Brown bearOP
Next responses me with 404 page / error
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Asian black bear
Share the code of one of the endpoints that yields a 404
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
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
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Asian black bear
And what does your middleware look like?
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
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
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Asian black bear
Then remove it first to see whether the API endpoint is reachable without Middleware
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Brown bearOP
hold on
Same shit
😦
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Asian black bear
How are you attempting to access the API? Via Postman, curl or in code using fetch?
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Brown bearOP
By the browser, but even using httpie for example dont work
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Asian black bear
So
http://localhost:3000/api/places
and http://localhost:3000/api/places/foo
both return 404?![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Brown bearOP
yeah
both
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Asian black bear
Did you configure some base URL or something similar?
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Brown bearOP
crazy man 🤯
on my next.config? Nope
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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.
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Brown bearOP
Oh shit jaja 😦