From 72caafe8b04e1cbc123d44d757fdc97640e4e6c4 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 19 Nov 2020 10:18:15 -0600 Subject: [PATCH] Fix service worker not loading (#2335) I removed this under the impression the default was to allow it anywhere but that's not the case. Since the service worker was already registered in my browser I never got the error during testing. --- src/node/routes/static.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/node/routes/static.ts b/src/node/routes/static.ts index cac4dd8c..22bdd8d2 100644 --- a/src/node/routes/static.ts +++ b/src/node/routes/static.ts @@ -52,6 +52,11 @@ router.get("/(:commit)(/*)?", async (req, res) => { res.header("Cache-Control", "public, max-age=31536000") } + // Without this the default is to use the directory the script loaded from. + if (req.headers["service-worker"]) { + res.header("service-worker-allowed", "/") + } + res.set("Content-Type", getMediaMime(resourcePath)) if (resourcePath.endsWith("manifest.json")) {