From f1fc5d8d45242c3b259ce216c0705e828a51fb2a Mon Sep 17 00:00:00 2001 From: Yuriy Andamasov Date: Wed, 22 Jul 2026 16:11:16 +0300 Subject: workers: html_handling none + worker index-mapping — RTD .html URL parity (smoke 307 fix) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workers/branch/src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'workers/branch/src') diff --git a/workers/branch/src/index.ts b/workers/branch/src/index.ts index d955d166..e9342c26 100644 --- a/workers/branch/src/index.ts +++ b/workers/branch/src/index.ts @@ -38,7 +38,16 @@ export function withDocsHeaders( export default { async fetch(request: Request, env: Env): Promise { const url = new URL(request.url); - const resp = await env.ASSETS.fetch(request); + // With assets html_handling "none", the runtime serves explicit .html URLs directly + // but does NOT map a directory URL ("/foo/") to its index.html — the worker must map + // trailing-slash URLs to index.html itself to preserve ReadTheDocs URL parity. + let assetRequest = request; + if (url.pathname.endsWith("/")) { + const mapped = new URL(url); + mapped.pathname = url.pathname + "index.html"; + assetRequest = new Request(mapped, request); + } + const resp = await env.ASSETS.fetch(assetRequest); return withDocsHeaders(resp, url.pathname, env); }, } satisfies ExportedHandler; -- cgit v1.2.3