sw.js: support calling /edit on a directory path

This commit is contained in:
Nicolas Wavrant 2020-07-10 08:41:30 +02:00
parent 8bbbe96c22
commit aaf4837aaa
1 changed files with 5 additions and 1 deletions

View File

@ -64,9 +64,13 @@ self.addEventListener('fetch', function(event) {
}
if (pathname.endsWith("/edit")) {
let offset_length = "/edit".length,
let offset_length = "/edit".length - 1, // -1 to keep the trailing slash
real_pathname = pathname.substring(0, pathname.length - offset_length);
if (real_pathname[real_pathname.length - 1] === "/") {
real_pathname = real_pathname + "index.html";
}
pathname = "/dev/";
hash = "#action=edit&path=" + real_pathname;
event.respondWith(Response.redirect(window.location.origin + pathname + hash));