seguimos
This commit is contained in:
@@ -17,9 +17,11 @@ services:
|
|||||||
- "traefik.enable=true"
|
- "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.entrypoints=websecure"
|
||||||
- "traefik.http.routers.musica-nucleoriofrio-public.tls.certresolver=letsencrypt"
|
- "traefik.http.routers.musica-nucleoriofrio-public.tls.certresolver=letsencrypt"
|
||||||
- "traefik.http.routers.musica-nucleoriofrio-public.priority=100"
|
- "traefik.http.routers.musica-nucleoriofrio-public.priority=100"
|
||||||
@@ -28,8 +30,19 @@ services:
|
|||||||
- "traefik.http.routers.musica-nucleoriofrio-public.service=musica-nucleoriofrio-service"
|
- "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.rule=Host(`musica.nucleoriofrio.com`)"
|
||||||
- "traefik.http.routers.musica-nucleoriofrio.entrypoints=websecure"
|
- "traefik.http.routers.musica-nucleoriofrio.entrypoints=websecure"
|
||||||
- "traefik.http.routers.musica-nucleoriofrio.tls.certresolver=letsencrypt"
|
- "traefik.http.routers.musica-nucleoriofrio.tls.certresolver=letsencrypt"
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ export default defineNuxtConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
// API Music list: Network-First with offline fallback
|
// 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$/,
|
urlPattern: /\/api\/music$/,
|
||||||
handler: 'NetworkFirst',
|
handler: 'NetworkFirst',
|
||||||
@@ -107,11 +111,18 @@ export default defineNuxtConfig({
|
|||||||
maxAgeSeconds: 60 * 5 // 5 minutes
|
maxAgeSeconds: 60 * 5 // 5 minutes
|
||||||
},
|
},
|
||||||
cacheableResponse: {
|
cacheableResponse: {
|
||||||
|
// Solo cachea respuestas exitosas (200)
|
||||||
|
// NO cachea 401/403 (sin autenticación)
|
||||||
statuses: [0, 200]
|
statuses: [0, 200]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// API Music files: Cache-First for downloaded tracks
|
// 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\/.+/,
|
urlPattern: /\/api\/music\/.+/,
|
||||||
handler: 'CacheFirst',
|
handler: 'CacheFirst',
|
||||||
@@ -122,14 +133,17 @@ export default defineNuxtConfig({
|
|||||||
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
|
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
|
||||||
},
|
},
|
||||||
cacheableResponse: {
|
cacheableResponse: {
|
||||||
|
// Solo cachea respuestas exitosas
|
||||||
|
// NO cachea 401/403/404
|
||||||
statuses: [0, 200, 206] // Include partial content
|
statuses: [0, 200, 206] // Include partial content
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
{
|
{
|
||||||
// Handle authentication errors gracefully
|
// Handle authentication errors gracefully
|
||||||
handlerDidError: async ({ request }) => {
|
handlerDidError: async ({ request }) => {
|
||||||
console.warn('[SW] Failed to fetch:', request.url)
|
console.warn('[SW] Failed to fetch (posible error de auth o red):', request.url)
|
||||||
// Return null to let the app handle the error
|
// Return null para que la app maneje el error
|
||||||
|
// La app puede mostrar mensaje de "requiere login" o "sin conexión"
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user