#Unable to reach my API endpoints

26 messages · Page 1 of 1 (latest)

strong salmon
#

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?

brisk rainBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

strong salmon
#

Next responses me with 404 page / error

fierce lichen
#

Share the code of one of the endpoints that yields a 404

strong salmon
#
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

fierce lichen
#

And what does your middleware look like?

strong salmon
#
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

fierce lichen
#

Then remove it first to see whether the API endpoint is reachable without Middleware

strong salmon
#

hold on

#

Same shit

#

😦

fierce lichen
#

How are you attempting to access the API? Via Postman, curl or in code using fetch?

strong salmon
#

By the browser, but even using httpie for example dont work

fierce lichen
#

So http://localhost:3000/api/places and http://localhost:3000/api/places/foo both return 404?

strong salmon
#

yeah

#

both

fierce lichen
#

Did you configure some base URL or something similar?

strong salmon
#

crazy man 🤯

#

on my next.config? Nope

fierce lichen
#

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.