importScripts('./public/js/standalone-routing.js');

const routing = self.LazySundayStandaloneRouting;
const standaloneRootUrl = routing.folderUrl(self.location.href);

self.addEventListener('install', event => {
  event.waitUntil(self.skipWaiting());
});

self.addEventListener('activate', event => {
  event.waitUntil(self.clients.claim());
});

self.addEventListener('fetch', event => {
  const mappedUrl = routing.mapRequestUrl(event.request.url, standaloneRootUrl);
  if (!mappedUrl) return;
  event.respondWith(fetch(new Request(mappedUrl, event.request)));
});
