Skip to content

Commit 4a4f3c1

Browse files
committed
install pass-thru for root requests
1 parent 15a698b commit 4a4f3c1

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

web/boot/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
}
4444

4545
navigator.serviceWorker.controller.postMessage({
46+
mode: map.mode,
4647
clear: map.clear,
4748
disable: map.disable,
4849
version: map.version || version

web/boot/service.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ async function _fetch(e) {
142142
}
143143

144144
if (url.pathname.endsWith("/")) {
145-
return e.respondWith(redirectOr404(appendURL(url, 'index.html').pathname));
146-
} else if (url.pathname.indexOf(".") < 0) {
147-
return e.respondWith(redirectOr404(appendURL(url, '/index.html').pathname));
145+
return e.respondWith(redirectToUrl(appendURL(url, 'index.html').pathname, request));
146+
} else if (url.pathname.indexOf(".") < 0 || url.pathname.endsWith("/boot")) {
147+
return e.respondWith(redirectToUrl(appendURL(url, '/index.html').pathname, request));
148148
} else {
149149
e.respondWith(fromCacheOrNetwork(request));
150150
}
@@ -155,16 +155,9 @@ function appendURL(url, append) {
155155
return new URL(url.origin + url.pathname + append + url.search);
156156
}
157157

158-
async function redirectOr404(path) {
159-
const cache = await cacheOpen;
160-
const hit = await cache.match(path, { ignoreSearch: true });
161-
if (hit) {
162-
if (debug) log('REDIRECT', path);
163-
return Response.redirect(path, 302);
164-
} else {
165-
if (debug) log('404', path);
166-
return new Response('Not Found', { status: 404, statusText: 'Not Found' });
167-
}
158+
async function redirectToUrl(path, request) {
159+
if (debug) log('REDIRECT', path);
160+
return Response.redirect(path, 302);
168161
}
169162

170163
async function fromCacheOrNetwork(req) {

0 commit comments

Comments
 (0)