fix(web): strip trailing slash from wildcard/custom-domain rewrite target
Root-path requests to a subdomain or custom domain rewrote to /menu/<slug>/ (trailing slash), which the [slug] dynamic route can't match — the app fell through to notFound() even for verified, published restaurants. Custom domains (e.g. ad.ayris.tech) always hit this since their only real traffic is the root path.
This commit is contained in:
@@ -17,8 +17,13 @@ export function middleware(req: NextRequest) {
|
||||
? hostname.replace(`.${ROOT_DOMAIN}`, "")
|
||||
: hostname; // custom domain — resolved to a slug via domains table at render time
|
||||
|
||||
// On the root path, req.nextUrl.pathname is "/" — appending it as-is would
|
||||
// rewrite to "/menu/<slug>/" (trailing slash), which the [slug] dynamic
|
||||
// route does not match. Only append the original path when it's non-root.
|
||||
const originalPath = req.nextUrl.pathname === "/" ? "" : req.nextUrl.pathname;
|
||||
|
||||
const url = req.nextUrl.clone();
|
||||
url.pathname = `/menu/${subdomain}${req.nextUrl.pathname}`;
|
||||
url.pathname = `/menu/${subdomain}${originalPath}`;
|
||||
return NextResponse.rewrite(url);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user