Middleware redirects the main tenant to the subdomain if the route doesn't exist.
Start the setup by running either npm run dev or npm run dev:proxy.
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
Middleware redirects the main tenant to the subdomain if the route doesn't exist.
http://localhost:3000/foo
. The middleware correctly treats this request asMain
, yet it redirects to the[subdomain]/page.tsx
page.Interestingly, if you access a deeper non-existent route like
http://localhost:3000/foo/bar
, the middleware correctly returns a 404 error page.