refactor nginx

Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
Omar Sánchez Pizarro
2026-01-21 00:30:13 +01:00
parent ed2107086c
commit 53928328d4
11 changed files with 394 additions and 78 deletions

View File

@@ -11,14 +11,14 @@ RUN npm ci
# Copiar código fuente
COPY . .
# Construir aplicación
# Construir aplicación con base /dashboard/
RUN npm run build
# Stage de producción - servir con nginx
FROM nginx:alpine
# Copiar archivos construidos
COPY --from=builder /app/dist /usr/share/nginx/html
# Copiar archivos construidos (ya incluyen el prefijo /dashboard en las rutas)
COPY --from=builder /app/dist /usr/share/nginx/html/dashboard
# Copiar configuración de nginx (se puede sobrescribir con volumen)
COPY nginx-dashboard.conf /etc/nginx/conf.d/default.conf

View File

@@ -10,15 +10,22 @@ server {
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript;
# SPA routing - todas las rutas del dashboard
location / {
try_files $uri $uri/ /index.html;
# Dashboard assets con prefijo /dashboard/
location /dashboard/ {
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# SPA routing - todas las rutas del dashboard
try_files $uri $uri/ /dashboard/index.html;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
# Redirigir raíz al dashboard
location = / {
return 301 /dashboard/;
}
}

View File

@@ -8,42 +8,24 @@ server {
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript;
# SPA routing
location / {
try_files $uri $uri/ /index.html;
# Dashboard assets con prefijo /dashboard/
location /dashboard/ {
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# SPA routing - todas las rutas del dashboard
try_files $uri $uri/ /dashboard/index.html;
}
# API proxy
location /api {
proxy_pass http://backend:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# WebSocket proxy
location /ws {
proxy_pass http://backend:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
# Redirigir raíz al dashboard
location = / {
return 301 /dashboard/;
}
}

View File

@@ -20,8 +20,8 @@ self.addEventListener('push', (event) => {
let notificationData = {
title: 'Wallabicher',
body: 'Tienes nuevas notificaciones',
icon: '/android-chrome-192x192.png',
badge: '/android-chrome-192x192.png',
icon: '/dashboard/android-chrome-192x192.png',
badge: '/dashboard/android-chrome-192x192.png',
tag: 'wallabicher-notification',
requireInteraction: false,
data: {}
@@ -89,7 +89,7 @@ self.addEventListener('notificationclick', (event) => {
} else {
// Si no hay URL, abrir la app
event.waitUntil(
clients.openWindow('/')
clients.openWindow('/dashboard/')
);
}
});

View File

@@ -105,8 +105,8 @@ app.mount('#app');
if ('serviceWorker' in navigator) {
window.addEventListener('load', async () => {
try {
const registration = await navigator.serviceWorker.register('/sw.js', {
scope: '/'
const registration = await navigator.serviceWorker.register('/dashboard/sw.js', {
scope: '/dashboard/'
});
console.log('Service Worker registrado:', registration.scope);
} catch (error) {

View File

@@ -2,7 +2,7 @@ import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { fileURLToPath, URL } from 'url';
export default defineConfig({
export default defineConfig(({ mode }) => ({
plugins: [vue()],
base: '/dashboard/',
resolve: {
@@ -12,7 +12,9 @@ export default defineConfig({
},
server: {
port: 3000,
proxy: {
host: true,
// Proxy solo para desarrollo local
proxy: mode === 'development' ? {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true,
@@ -21,7 +23,7 @@ export default defineConfig({
target: 'ws://localhost:3001',
ws: true,
},
},
} : undefined,
},
});
}));