seguimos
All checks were successful
build-and-deploy / build (push) Successful in 23s
build-and-deploy / deploy (push) Successful in 2s

This commit is contained in:
2025-10-11 18:43:53 -06:00
parent 811b525cfc
commit c56f06034e
2 changed files with 32 additions and 5 deletions

View File

@@ -17,9 +17,11 @@ services:
- "traefik.enable=true"
# ==========================================
# Router público para recursos PWA (sin autenticación)
# Router público para recursos PWA ESTÁTICOS (sin autenticación)
# IMPORTANTE: Solo assets estáticos (JS, CSS, iconos, manifest, SW)
# Las APIs (/api/*) NO están aquí - están protegidas abajo
# ==========================================
- "traefik.http.routers.musica-nucleoriofrio-public.rule=Host(`musica.nucleoriofrio.com`) && (PathPrefix(`/_nuxt`) || PathPrefix(`/assets`) || Path(`/sw.js`) || PathPrefix(`/workbox-`) || Path(`/manifest.webmanifest`) || Path(`/manifest.json`) || Path(`/robots.txt`) || Path(`/favicon.ico`) || Path(`/logo.png`) || Path(`/logo-192.png`) || Path(`/logo-512.png`) || Path(`/logo-maskable-512.png`) || Path(`/icon.svg`))"
- "traefik.http.routers.musica-nucleoriofrio-public.rule=Host(`musica.nucleoriofrio.com`) && (PathPrefix(`/_nuxt`) || PathPrefix(`/assets`) || Path(`/sw.js`) || PathPrefix(`/workbox-`) || Path(`/manifest.webmanifest`) || Path(`/manifest.json`) || Path(`/robots.txt`) || Path(`/favicon.ico`) || Path(`/logo.png`) || Path(`/logo-192.png`) || Path(`/logo-512.png`) || Path(`/logo-maskable-512.png`) || Path(`/icon.svg`)) && !PathPrefix(`/api/`)"
- "traefik.http.routers.musica-nucleoriofrio-public.entrypoints=websecure"
- "traefik.http.routers.musica-nucleoriofrio-public.tls.certresolver=letsencrypt"
- "traefik.http.routers.musica-nucleoriofrio-public.priority=100"
@@ -28,8 +30,19 @@ services:
- "traefik.http.routers.musica-nucleoriofrio-public.service=musica-nucleoriofrio-service"
# ==========================================
# Router protegido para el resto de la app
# Router protegido para el resto de la app (incluye /api/music)
# ==========================================
# IMPORTANTE: Todas las APIs (/api/*) pasan por aquí
# - /api/music → Lista de canciones (requiere auth)
# - /api/music/:name → Descarga de canción (requiere auth)
# - Página principal (/) → Requiere auth
#
# Flujo PWA + Authentik:
# 1. Usuario sin auth intenta acceder → Authentik redirige a login
# 2. Usuario con auth accede → Puede listar y descargar música
# 3. Música descargada se guarda en IndexedDB (stores/music.ts)
# 4. Usuario offline → Service Worker sirve desde cache
# 5. Usuario offline SIN cache → Falla graciosamente (no puede descargar sin auth)
- "traefik.http.routers.musica-nucleoriofrio.rule=Host(`musica.nucleoriofrio.com`)"
- "traefik.http.routers.musica-nucleoriofrio.entrypoints=websecure"
- "traefik.http.routers.musica-nucleoriofrio.tls.certresolver=letsencrypt"

View File

@@ -96,6 +96,10 @@ export default defineNuxtConfig({
}
},
// API Music list: Network-First with offline fallback
// IMPORTANTE: Esta ruta REQUIERE autenticación via Authentik
// - Online + Autenticado: Fetches desde servidor (pasa por Authentik)
// - Online + NO autenticado: Authentik redirige a login (401/403)
// - Offline: Usa cache si existe
{
urlPattern: /\/api\/music$/,
handler: 'NetworkFirst',
@@ -107,11 +111,18 @@ export default defineNuxtConfig({
maxAgeSeconds: 60 * 5 // 5 minutes
},
cacheableResponse: {
// Solo cachea respuestas exitosas (200)
// NO cachea 401/403 (sin autenticación)
statuses: [0, 200]
}
}
},
// API Music files: Cache-First for downloaded tracks
// IMPORTANTE: Esta ruta REQUIERE autenticación via Authentik
// - Cache hit: Sirve desde cache (offline-ready, no requiere auth)
// - Cache miss + Online + Autenticado: Descarga y cachea
// - Cache miss + Online + NO autenticado: Falla con 401/403
// - Cache miss + Offline: Falla (app debe manejar el error)
{
urlPattern: /\/api\/music\/.+/,
handler: 'CacheFirst',
@@ -122,14 +133,17 @@ export default defineNuxtConfig({
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
},
cacheableResponse: {
// Solo cachea respuestas exitosas
// NO cachea 401/403/404
statuses: [0, 200, 206] // Include partial content
},
plugins: [
{
// Handle authentication errors gracefully
handlerDidError: async ({ request }) => {
console.warn('[SW] Failed to fetch:', request.url)
// Return null to let the app handle the error
console.warn('[SW] Failed to fetch (posible error de auth o red):', request.url)
// Return null para que la app maneje el error
// La app puede mostrar mensaje de "requiere login" o "sin conexión"
return null
}
}