// Self-destructing service worker.
//
// buildmymcpserver.com previously ran on GoDaddy Airo, which installed a
// Workbox service worker that pre-cached GoDaddy's pages. That worker keeps
// serving stale GoDaddy content in browsers that visited the parked domain.
// Our app does not use a service worker — this file exists only so that when
// such a browser checks sw.js for an update it receives this script, which
// wipes the caches and unregisters itself.
self.addEventListener('install', () => self.skipWaiting());

self.addEventListener('activate', (event) => {
  event.waitUntil(
    (async () => {
      const keys = await caches.keys();
      await Promise.all(keys.map((k) => caches.delete(k)));
      await self.registration.unregister();
      const clients = await self.clients.matchAll({ type: 'window' });
      for (const client of clients) {
        client.navigate(client.url);
      }
    })(),
  );
});
