From 2bbe50991dd355298c1db39b33f67c645662ab34 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Sat, 28 Feb 2026 23:11:49 -0800 Subject: [PATCH] fix: exclude server paths from space-to-subdomain redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bare-domain routing logic was redirecting all multi-segment paths like /api/modules → api.rspace.online/modules. Add exclusion for known server path prefixes (api, admin, admin-data, admin-action, .well-known) so they fall through to Hono route handlers instead. Co-Authored-By: Claude Opus 4.6 --- server/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/index.ts b/server/index.ts index 6d69006a..2b6f2f2a 100644 --- a/server/index.ts +++ b/server/index.ts @@ -865,9 +865,6 @@ app.get("/create-space", async (c) => { app.get("/new", (c) => c.redirect("/create-space", 301)); // ── Admin dashboard & API ── -// NOTE: Cloudflare has a wildcard rule that redirects any multi-segment path -// (rspace.online/foo/bar → foo.rspace.online/bar), so all admin endpoints -// must be single-segment paths. Use POST /admin-action for mutations. const ADMIN_DIDS = (process.env.ADMIN_DIDS || "").split(",").filter(Boolean); @@ -1331,7 +1328,9 @@ const server = Bun.serve({ // 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) { + // Skip redirect for known server paths (api, admin, etc.) + const serverPaths = new Set(["api", "admin", "admin-data", "admin-action", ".well-known"]); + if (!knownModuleIds.has(firstSegment) && !serverPaths.has(firstSegment) && pathSegments.length >= 2) { const space = firstSegment; const rest = "/" + pathSegments.slice(1).join("/"); const baseDomain = hostClean.replace(/^www\./, "");