From 988fc4f8932e2b6ed6d8f7f3a68b463f10c30b02 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Wed, 11 Mar 2026 18:02:02 -0700 Subject: [PATCH] fix: handle subdomain URLs that already include space prefix When accessing demo.rspace.online/demo/rcart/pay/123, the subdomain router was prepending the space again, creating /demo/demo/rcart/pay/123 which returned 404. Now detects when first path segment matches the subdomain and passes through without double-prefixing. Co-Authored-By: Claude Opus 4.6 --- server/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/index.ts b/server/index.ts index 2e1e461..3f2f82b 100644 --- a/server/index.ts +++ b/server/index.ts @@ -2405,6 +2405,14 @@ const server = Bun.serve({ } } + // If first segment already matches the subdomain (space slug), + // pass through directly — URL already has /{space}/... prefix + // e.g. demo.rspace.online/demo/rcart/pay/123 → /demo/rcart/pay/123 + if (pathSegments[0].toLowerCase() === subdomain) { + const rewrittenUrl = new URL(url.pathname + url.search, `http://localhost:${PORT}`); + return app.fetch(new Request(rewrittenUrl, req)); + } + // Normalize module ID to lowercase (rTrips → rtrips) const normalizedPath = "/" + pathSegments.map((seg, i) => i === 0 ? seg.toLowerCase() : seg