diff --git a/src/gateway/public-gateway.mjs b/src/gateway/public-gateway.mjs index 34aec4d..28661b8 100644 --- a/src/gateway/public-gateway.mjs +++ b/src/gateway/public-gateway.mjs @@ -171,7 +171,14 @@ async function serve(res, name, reqPath, baseHref) { case "s3": { const sub = subFolder(name); let base = r.s3; if (base.endsWith("/") && sub) base += sub + "/"; - const key = base.endsWith("/") ? base + (reqPath === "/" ? "index.html" : reqPath.slice(1)) : base; + // Auto-index directory paths. S3 has no dir listing, so `/tools/` + // would 404 (NoSuchKey) without this — matches how nginx handles + // `try_files … /index.html` and how Ariadne's bnsd.js rewrites the + // same URLs client-side. + const rel = reqPath === "/" ? "index.html" + : 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}`); const buf = Buffer.from(await up.arrayBuffer()); let ct = up.headers.get("content-type"); if (!ct || ct === "application/octet-stream") ct = guess(key);