Add offline fallback page for PWA
- Create offline.html with user-friendly offline message - Auto-redirect when connection is restored - Use offline.html as navigateFallback instead of root - Include offline.html in PWA assets for precaching This ensures users see a proper offline page when opening the app without connection, instead of a browser error.
This commit is contained in:
@@ -22,7 +22,7 @@ export default defineNuxtConfig({
|
|||||||
|
|
||||||
pwa: {
|
pwa: {
|
||||||
registerType: 'autoUpdate',
|
registerType: 'autoUpdate',
|
||||||
includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'icon.svg'],
|
includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'icon.svg', 'offline.html'],
|
||||||
manifest: {
|
manifest: {
|
||||||
name: 'Plantilla Nuxt + Authentik',
|
name: 'Plantilla Nuxt + Authentik',
|
||||||
short_name: 'NuxtAuth',
|
short_name: 'NuxtAuth',
|
||||||
@@ -72,7 +72,7 @@ export default defineNuxtConfig({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
workbox: {
|
workbox: {
|
||||||
navigateFallback: '/',
|
navigateFallback: '/offline.html',
|
||||||
navigateFallbackDenylist: [/^\/api\//, /^\/authentik\//],
|
navigateFallbackDenylist: [/^\/api\//, /^\/authentik\//],
|
||||||
globPatterns: ['**/*.{js,css,html,png,svg,ico,json}'],
|
globPatterns: ['**/*.{js,css,html,png,svg,ico,json}'],
|
||||||
cleanupOutdatedCaches: true,
|
cleanupOutdatedCaches: true,
|
||||||
|
|||||||
126
nuxt4/public/offline.html
Normal file
126
nuxt4/public/offline.html
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Modo Offline - Plantilla Nuxt + Authentik</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
background: white;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 48px 32px;
|
||||||
|
max-width: 480px;
|
||||||
|
width: 100%;
|
||||||
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
margin: 0 auto 24px;
|
||||||
|
background: #f3f4f6;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 28px;
|
||||||
|
color: #1f2937;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #6b7280;
|
||||||
|
line-height: 1.6;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 14px 32px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.2s, box-shadow 0.2s;
|
||||||
|
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 24px;
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: #fef3c7;
|
||||||
|
color: #92400e;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="icon">📡</div>
|
||||||
|
<h1>Modo Offline</h1>
|
||||||
|
<p>
|
||||||
|
No tienes conexión a internet en este momento. Esta aplicación requiere conexión para autenticarse con Authentik.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Por favor, verifica tu conexión e intenta nuevamente.
|
||||||
|
</p>
|
||||||
|
<button class="button" onclick="window.location.reload()">
|
||||||
|
Reintentar
|
||||||
|
</button>
|
||||||
|
<div class="status">
|
||||||
|
⚠️ Sin conexión
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Verificar conexión cada 3 segundos
|
||||||
|
setInterval(() => {
|
||||||
|
if (navigator.onLine) {
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
// Escuchar evento de conexión
|
||||||
|
window.addEventListener('online', () => {
|
||||||
|
window.location.href = '/';
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user