service-worker: don't serve index.html for static

This fixes issues where the index.html page can be served if we have
something that requests a static resource that does not exist. In the
worst case, this would the app appear recursively in the docs pane.

Also remove some unnecessary typing while we are touching this.
This commit is contained in:
David Lechner
2022-12-08 17:10:47 -06:00
committed by David Lechner
parent 6dc03ad911
commit 74d8a258fb
+6 -1
View File
@@ -34,12 +34,17 @@ precacheAndRoute(self.__WB_MANIFEST, { ignoreURLParametersMatching: [/.*/] });
const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$');
registerRoute(
// Return false to exempt requests from being fulfilled by index.html.
({ request, url }: { request: Request; url: URL }) => {
({ request, url }) => {
// If this isn't a navigation, skip.
if (request.mode !== 'navigate') {
return false;
}
// If this is a URL for a static resource, skip.
if (url.pathname.startsWith('/static/')) {
return false;
}
// If this is a URL that starts with /_, skip.
if (url.pathname.startsWith('/_')) {
return false;