feat: add path-based community routing under subdomain namespaces

cca.rspace.online/campaign/demo now loads the campaign-demo community.
Path segments are joined with hyphens to derive the slug. Subdomain
acts as a brand namespace; root path still loads the subdomain slug.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-02-18 14:20:57 -07:00
parent 533ce89cea
commit 73aee64401
2 changed files with 28 additions and 3 deletions

View File

@ -210,10 +210,24 @@ const server = Bun.serve<WSData>({
}
// Community canvas route (subdomain detected)
// Supports path-based slugs: cca.rspace.online/campaign/demo → slug "campaign-demo"
if (subdomain) {
const community = await loadCommunity(subdomain);
const pathSegments = url.pathname.split("/").filter(Boolean);
// Derive slug: path segments joined with "-", or subdomain if at root
const slug = pathSegments.length > 0 ? pathSegments.join("-") : subdomain;
const community = await loadCommunity(slug);
if (!community) {
return new Response("Community not found", { status: 404 });
// Path slug not found — fall back to subdomain slug if path was given
if (pathSegments.length > 0) {
const fallback = await loadCommunity(subdomain);
if (!fallback) {
return new Response("Community not found", { status: 404 });
}
} else {
return new Response("Community not found", { status: 404 });
}
}
// Serve canvas.html for community

View File

@ -343,11 +343,22 @@
FolkSocialPost.define();
// Get community info from URL
// Supports path-based slugs: cca.rspace.online/campaign/demo → slug "campaign-demo"
const hostname = window.location.hostname;
const subdomain = hostname.split(".")[0];
const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1";
const urlParams = new URLSearchParams(window.location.search);
const communitySlug = urlParams.get("space") || (isLocalhost ? "demo" : subdomain);
const pathSegments = window.location.pathname.split("/").filter(Boolean);
const ignorePaths = ["canvas", "settings", "api"];
const cleanSegments = pathSegments.filter(s => !ignorePaths.includes(s));
let communitySlug = urlParams.get("space");
if (!communitySlug && cleanSegments.length > 0) {
communitySlug = cleanSegments.join("-");
} else if (!communitySlug) {
communitySlug = isLocalhost ? "demo" : subdomain;
}
// Update UI
document.getElementById("community-name").textContent = communitySlug;