Closed ncw closed 2 years ago
Just realised this is broken... Will upload a fixed version shortly!
Fixed now!
It might be nicer to have it support absolute paths like /index.html
, but that might need a better name like FALLBACK_PATH
or FALLBACK_FILE
.
This looks good! All that's missing is adding
INDEX_FILE?: string
to theEnv
interface at the top of index.ts.
I missed that. I've never written any typescript before ;-)
Might also need to check if
INDEX_FILE
is undefined instead of""
as well.
Is this a good way?
@@ -36,7 +37,7 @@ export default {
}
const url = new URL(request.url);
- if (env.INDEX_FILE === "" && url.pathname === "/") {
+ if (!env.INDEX_FILE && url.pathname === "/") {
return new Response("OK");
}
@@ -51,7 +52,7 @@ export default {
var path = (env.PATH_PREFIX || "") + decodeURIComponent(url.pathname.substring(1));
// Look for index file if asked for a directory
- if (env.INDEX_FILE !== "" && (path.endsWith("/") || path === "")) {
+ if (env.INDEX_FILE && (path.endsWith("/") || path === "")) {
path += env.INDEX_FILE;
}
It might be nicer to have it support absolute paths like
/index.html
, but that might need a better name likeFALLBACK_PATH
orFALLBACK_FILE
.
I'm not sure I understand you here. An absolute path like /index.html
would imply re-using the /index.html
for every sub directory wouldn't it? I'm not sure how that would be used.
Is this a good way?
Yup, looks good!
I'm not sure I understand you here. An absolute path like /index.html would imply re-using the /index.html for every sub directory wouldn't it? I'm not sure how that would be used.
Yeah, in hindsight an absolute path for subdirectory fallbacks wouldn't be very useful. We probably don't need that.
I've updated that. PTAL :-)
Just tested this and it's working! Thanks for the PR!
Thank you for a great project 🙂
This then allow static web sites to be served properly from an R2 bucket.