From 2c9c36c40c2d894a8ebffe0f0170182799032753 Mon Sep 17 00:00:00 2001 From: Heimdall Date: Wed, 1 Apr 2026 04:47:54 +0000 Subject: [PATCH] Fix SSG compatibility: fallback /path.html to /path/index.html Astro and other SSG frameworks generate /path/index.html instead of /path.html. Added fallback logic so /products resolves to /products/index.html when /products.html doesn't exist in R2. --- src/worker.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/worker.js b/src/worker.js index 14f4c77..18dc9f6 100644 --- a/src/worker.js +++ b/src/worker.js @@ -523,7 +523,17 @@ export default { const key = `sites/${customer}${filePath}`; try { - const object = await env.BUCKET.get(key); + let object = await env.BUCKET.get(key); + + // Fallback: /path.html β†’ /path/index.html (Astro λ“± SSG ν˜Έν™˜) + if (!object && filePath.endsWith('.html') && filePath !== '/index.html') { + const dirPath = filePath.replace(/\.html$/, '/index.html'); + const dirKey = `sites/${customer}${dirPath}`; + object = await env.BUCKET.get(dirKey); + if (object) { + filePath = dirPath; + } + } if (!object) { if (filePath === '/index.html') {