diff --git a/src/gateway/public-gateway.mjs b/src/gateway/public-gateway.mjs index 92736a1..a5627e6 100644 --- a/src/gateway/public-gateway.mjs +++ b/src/gateway/public-gateway.mjs @@ -234,7 +234,17 @@ async function serve(res, name, reqPath, baseHref) { : reqPath.endsWith("/") ? reqPath.slice(1) + "index.html" : reqPath.slice(1); const key = base.endsWith("/") ? base + rel : base; - const up = await aws.fetch(`${S3_ENDPOINT}/${key}`); + let up = await aws.fetch(`${S3_ENDPOINT}/${key}`); + // SPA fallback — if the extension-less path 404s, serve the domain's + // own index.html so client-side routers (History API) can pick up + // /katalogos, /anthemus, /artemision, etc. under any BNS mount. + // We only fall back when the requested path has no file extension — + // requests for missing images / json / js still 404 as they should. + if (up.status === 404 && !/\.[a-z0-9]+$/i.test(reqPath) && reqPath !== "/") { + const fallbackKey = (base.endsWith("/") ? base : base + "/") + "index.html"; + const fb = await aws.fetch(`${S3_ENDPOINT}/${fallbackKey}`); + if (fb.ok) { up = fb; } + } const buf = Buffer.from(await up.arrayBuffer()); let ct = up.headers.get("content-type"); if (!ct || ct === "application/octet-stream") ct = guess(key); if (ct.includes("text/html")) { res.writeHead(up.status, { "content-type": ct }); return res.end(injectBase(buf.toString("utf8"), baseHref)); }