GGCodeLatam / next-multitenant-2024

Tutorial for multi-tenant apps with next js 14, supabase and cloudflare
18 stars 7 forks source link

Middleware redirects to the subdomain if the provided route doesn't exist #1

Open Brainisthekey opened 4 months ago

Brainisthekey commented 4 months ago

Middleware redirects the main tenant to the subdomain if the route doesn't exist.

  1. Start the setup by running either npm run dev or npm run dev:proxy.
  2. Try accessing a non-existent route, such as http://localhost:3000/foo. The middleware correctly treats this request as Main, yet it redirects to the [subdomain]/page.tsx page.
    [0] Middleware: Hostname: localhost
    [0] Middleware: Subdomain: null
    [0] Middleware: Main domain detected, passing through
    [0] SubdomainPage: Rendering page for subdomain: foo
    [0] SubdomainPage: Tenant retrieved: null
    [0] SubdomainPage: Tenant not found, redirecting to 404
    [0] SubdomainPage: Error fetching tenant: Error: NEXT_NOT_FOUND
    [0]     at notFound (webpack-internal:///(rsc)/./node_modules/next/dist/client/components/not-found.js:23:19)
    [0]     at SubdomainPage (webpack-internal:///(rsc)/./app/[subdomain]/page.tsx:24:70) {
    [0]   digest: 'NEXT_NOT_FOUND'
    [0] }
    [0]  GET /foo 200 in 212ms
    [0]  GET /favicon.ico 200 in 8ms

Interestingly, if you access a deeper non-existent route like http://localhost:3000/foo/bar, the middleware correctly returns a 404 error page.

[0] Middleware: Hostname: localhost
[0] Middleware: Subdomain: null
[0] Middleware: Main domain detected, passing through
[0]  GET /foo/bar 404 in 28ms
SMILES00714 commented 1 month ago

Hello, I am using your template and it always saying Internal error.