Next.js Discord

Discord Forum

Unable to reach my API endpoints

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Avatar
Brown bearOP
Hello folks this is my tree:

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