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 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-03-11 18:02:02 -07:00
parent 8040c30756
commit 988fc4f893
1 changed files with 8 additions and 0 deletions

View File

@ -2405,6 +2405,14 @@ const server = Bun.serve<WSData>({
}
}
// 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