Merge branch 'dev'

This commit is contained in:
Jeff Emmett 2026-02-27 16:20:44 -08:00
commit 1cc18a06e5
1 changed files with 16 additions and 3 deletions

View File

@ -1124,15 +1124,17 @@ const server = Bun.serve<WSData>({
return app.fetch(rewrittenReq);
}
// ── Bare-domain module routes: rspace.online/{moduleId}[/...] ──
// Exact module path → landing page; sub-paths rewrite to /demo/...
// ── Bare-domain routing: rspace.online/{...} ──
if (!subdomain && hostClean.includes("rspace.online")) {
const pathSegments = url.pathname.split("/").filter(Boolean);
if (pathSegments.length >= 1) {
const firstSegment = pathSegments[0];
const allModules = getAllModules();
const knownModuleIds = new Set(allModules.map((m) => m.id));
const mod = allModules.find((m) => m.id === firstSegment);
if (mod) {
// rspace.online/{moduleId} → landing page
if (pathSegments.length === 1) {
// 1. Check for inline rich landing page
if (mod.landingPage) {
@ -1157,12 +1159,23 @@ const server = Bun.serve<WSData>({
});
return new Response(html, { headers: { "Content-Type": "text/html" } });
}
// Sub-paths → rewrite to /demo/{moduleId}/...
// rspace.online/{moduleId}/sub-path → rewrite to demo space internally
const rewrittenPath = `/demo${url.pathname}`;
const rewrittenUrl = new URL(rewrittenPath + url.search, `http://localhost:${PORT}`);
const rewrittenReq = new Request(rewrittenUrl, req);
return app.fetch(rewrittenReq);
}
// rspace.online/{space}/{...} → redirect to {space}.rspace.online/{...}
// (space is not a module ID — it's a space slug, canonicalize to subdomain)
if (!knownModuleIds.has(firstSegment) && pathSegments.length >= 2) {
const space = firstSegment;
const rest = "/" + pathSegments.slice(1).join("/");
const baseDomain = hostClean.replace(/^www\./, "");
return Response.redirect(
`${url.protocol}//${space}.${baseDomain}${rest}${url.search}`, 301
);
}
}
}