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.
This commit is contained in:
@@ -523,7 +523,17 @@ export default {
|
|||||||
const key = `sites/${customer}${filePath}`;
|
const key = `sites/${customer}${filePath}`;
|
||||||
|
|
||||||
try {
|
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 (!object) {
|
||||||
if (filePath === '/index.html') {
|
if (filePath === '/index.html') {
|
||||||
|
|||||||
Reference in New Issue
Block a user