038e09b202
specially when running a multi-arch cluster and HA with poor observability. a `time.Duration` was being casted to an `int` (because I clearly have no clue of what I'm doing). All is well on 64-bit processors, but 32-bit processors choke on the very long micro-second precision int, overflow, and turn `7d`, around `604800` seconds into `-114753536` seconds, which the browser happily (and correctly) turns into a cookie sent to /dev/null. lol.
32 lines
893 B
JavaScript
32 lines
893 B
JavaScript
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright © 2022 Roberto Hidalgo <nidito@un.rob.mx>
|
|
importScripts(
|
|
'https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js'
|
|
);
|
|
|
|
workbox.loadModule('workbox-strategies');
|
|
|
|
self.addEventListener("install", event => {
|
|
console.log("Service worker installed");
|
|
|
|
const urlsToCache = ["/login", "/", "index.css", "/index.js", "/login.js", "/webauthn.js"];
|
|
event.waitUntil(
|
|
caches.open("assets")
|
|
.then(cache => {
|
|
return cache.addAll(urlsToCache);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener("activate", event => {
|
|
console.log("Service worker activated");
|
|
});
|
|
|
|
|
|
self.addEventListener('fetch', event => {
|
|
if (event.request.url.endsWith('.js') || event.request.url.endsWith('.css')) {
|
|
const cacheFirst = new workbox.strategies.CacheFirst();
|
|
event.respondWith(cacheFirst.handle({request: event.request}));
|
|
}
|
|
});
|