diff --git a/docker-compose.yml b/docker-compose.yml index 6a39ad6..f6fa12f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ + version: "3.9" services: @@ -35,8 +36,8 @@ - "traefik.http.services.wifi-nucleoriofrio-service.loadbalancer.responseforwarding.flushinterval=1ms" - "traefik.http.services.wifi-nucleoriofrio-service.loadbalancer.serverstransport=wifi-transport@file" - # Router 1: Público (assets estáticos, manifest, icons) - SIN autenticación - ALTA PRIORIDAD - - "traefik.http.routers.wifi-nucleoriofrio-public.rule=Host(`wifi.nucleoriofrio.com`) && (PathPrefix(`/assets`) || PathPrefix(`/.well-known`) || PathPrefix(`/icons`) || Path(`/manifest.webmanifest`) || Path(`/favicon.ico`) || Path(`/vite.svg`))" + # Router 1: Público (assets, manifest, icons, callback de Authentik) - SIN autenticación - ALTA PRIORIDAD + - "traefik.http.routers.wifi-nucleoriofrio-public.rule=Host(`wifi.nucleoriofrio.com`) && (PathPrefix(`/assets`) || PathPrefix(`/.well-known`) || PathPrefix(`/icons`) || PathPrefix(`/outpost.goauthentik.io`) || Path(`/manifest.webmanifest`) || Path(`/favicon.ico`) || Path(`/vite.svg`) || Path(`/sw.js`))" - "traefik.http.routers.wifi-nucleoriofrio-public.entrypoints=websecure" - "traefik.http.routers.wifi-nucleoriofrio-public.tls.certresolver=letsencrypt" - "traefik.http.routers.wifi-nucleoriofrio-public.service=wifi-nucleoriofrio-service" diff --git a/frontend/public/sw.js b/frontend/public/sw.js index c551f71..317e2b3 100644 --- a/frontend/public/sw.js +++ b/frontend/public/sw.js @@ -1,5 +1,5 @@ // Nombre del caché para la aplicación -const CACHE_NAME = 'radius-nucleo-cache-v1'; +const CACHE_NAME = 'radius-nucleo-cache-v2'; // Archivos que se almacenarán en caché durante la instalación const URLS_TO_CACHE = [ @@ -27,8 +27,31 @@ self.addEventListener('install', (event) => { ); }); +// Evento de activación: limpia los caches antiguos +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((cacheNames) => { + return Promise.all( + cacheNames.map((cacheName) => { + if (cacheName !== CACHE_NAME) { + return caches.delete(cacheName); + } + }) + ); + }) + ); +}); + // Evento de recuperación (fetch): responde desde la caché si existe, si no, recupera de la red self.addEventListener('fetch', (event) => { + // Excluir las peticiones a /api/* del Service Worker + // Estas peticiones requieren autenticación y no deben ser cacheadas + const url = new URL(event.request.url); + if (url.pathname.startsWith('/api/')) { + // Dejar que el navegador maneje las peticiones de API normalmente + return; + } + event.respondWith( caches.match(event.request) .then((response) => {