diff --git a/Elecciones-Web/frontend/Dockerfile b/Elecciones-Web/frontend/Dockerfile index a307ad8..e55b7d9 100644 --- a/Elecciones-Web/frontend/Dockerfile +++ b/Elecciones-Web/frontend/Dockerfile @@ -27,8 +27,8 @@ FROM nginx:1.25-alpine # al directorio por defecto donde Nginx sirve los archivos. COPY --from=build /app/dist /usr/share/nginx/html -# Exponemos el puerto 80 (el puerto por defecto de Nginx). -EXPOSE 80 +# Copiamos nuestra configuración de Nginx para manejar el enrutamiento de la SPA +COPY frontend.nginx.conf /etc/nginx/conf.d/default.conf -# El comando por defecto de la imagen de Nginx ya es iniciar el servidor, -# así que no necesitamos un CMD o ENTRYPOINT. \ No newline at end of file +# Exponemos el puerto 80 (el puerto por defecto de Nginx). +EXPOSE 80 \ No newline at end of file diff --git a/Elecciones-Web/frontend/frontend.nginx.conf b/Elecciones-Web/frontend/frontend.nginx.conf new file mode 100644 index 0000000..d1f6335 --- /dev/null +++ b/Elecciones-Web/frontend/frontend.nginx.conf @@ -0,0 +1,18 @@ +# frontend-admin/frontend.nginx.conf + +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location ~* \.(?:css|js|jpg|jpeg|gif|png|ico|svg|woff|woff2)$ { + expires 1y; + add_header Cache-Control "public"; + } +} \ No newline at end of file diff --git a/Elecciones-Web/frontend/public/bootstrap.js b/Elecciones-Web/frontend/public/bootstrap.js index 3fbbc41..ce95a18 100644 --- a/Elecciones-Web/frontend/public/bootstrap.js +++ b/Elecciones-Web/frontend/public/bootstrap.js @@ -30,7 +30,7 @@ // 1. Obtener el manifest.json desde la ruta base detectada const response = await fetch(`${WIDGETS_HOST}/manifest.json`); if (!response.ok) { - throw new Error('No se pudo cargar el manifest de los widgets. (404 Not Found)'); + throw new Error('No se pudo cargar el manifest. (404 Not Found)'); } const manifest = await response.json(); @@ -53,20 +53,10 @@ // 4. Cargar el JS principal await loadScript(jsUrl); - - // 5. El addEventListener ya no es necesario aquí, el consumidor lo añade. - // Si quiere que sea totalmente automático, puede añadirlo: - window.addEventListener('load', function () { - if (window.EleccionesWidgets && typeof window.EleccionesWidgets.render === 'function') { - window.EleccionesWidgets.render(); - } - }); } catch (error) { console.error('Error al inicializar los widgets de Elecciones:', error); } } - initWidgets(); - })(); \ No newline at end of file