From 77eecd53ac0c5a57dd8562c4955de141015c1304 Mon Sep 17 00:00:00 2001 From: AyrisAI Date: Thu, 20 Aug 2026 05:18:59 +0300 Subject: [PATCH] fix(web): strip trailing slash from wildcard/custom-domain rewrite target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root-path requests to a subdomain or custom domain rewrote to /menu// (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. --- apps/web/src/middleware.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.ts index bb3763a..ffcf0ac 100644 --- a/apps/web/src/middleware.ts +++ b/apps/web/src/middleware.ts @@ -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//" (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); }