diff --git a/server/index.ts b/server/index.ts index 6a66099f..2a8708a0 100644 --- a/server/index.ts +++ b/server/index.ts @@ -3664,6 +3664,37 @@ app.get("/:space", (c) => { return c.redirect("/", 302); }); +// ── Custom 404 page ── +app.notFound((c) => { + const path = c.req.path; + // API routes: return JSON 404 + if (path.startsWith("/api/") || c.req.header("accept")?.includes("application/json")) { + return c.json({ error: "Not found" }, 404); + } + return c.html(` + + + +Page Not Found | rSpace + + +
+

404

+

This page doesn't exist — it may have moved or the URL might be wrong.

+Back to rSpace +

${path}

+
`, 404); +}); + // ── WebSocket types ── interface WSData { communitySlug: string; @@ -4343,11 +4374,11 @@ const server = Bun.serve({ if (shellResponse.status === 200) return shellResponse; } - // Non-module path — try canvas/index SPA fallback - const canvasHtml = await serveStatic("canvas.html"); - if (canvasHtml) return canvasHtml; - const indexHtml = await serveStatic("index.html"); - if (indexHtml) return indexHtml; + // Canvas SPA fallback (only for /rspace sub-paths, not general 404s) + if (parts[0] === "rspace" || (subdomain && parts[0] === "rspace")) { + const canvasHtml = await serveStatic("canvas.html"); + if (canvasHtml) return canvasHtml; + } } }