diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 5a574b3..929593f 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -2,49 +2,53 @@ # Docker Comose para entorno de desarrollo o development. services: - gateway: - image: nginx:alpine - container_name: suitecoffee-gateway + + nginx-proxy-manager: + image: jc21/nginx-proxy-manager:latest + container_name: nginx-proxy-manager + restart: unless-stopped depends_on: suitecoffee-app: condition: service_healthy suitecoffee-auth: condition: service_healthy ports: - - "80:80" # único puerto público (agregá 443 si después sumás TLS) + - "80:80" # HTTP público + - "81:81" # UI de administración NPM + - "443:443" # HTTPS público volumes: - - ./gateway/nginx.conf:/etc/nginx/nginx.conf:ro + - npm_data:/data # config + DB (SQLite) + - npm_letsencrypt:/etc/letsencrypt networks: - suitecoffee-net - restart: unless-stopped suitecoffee-app: - container_name: suitecoffee-app - depends_on: - suitecoffee-db: - condition: service_healthy - suitecoffee-tenants: - condition: service_healthy - build: - context: ./services/app - dockerfile: Dockerfile.development - volumes: - - ./services/app:/app - env_file: - - ./services/app/.env.development - environment: - - NODE_ENV=${NODE_ENV} - command: npm run dev - healthcheck: - # IMPORTANTE: asegurate de tener curl instalado en la imagen de app (ver nota abajo) - test: ["CMD-SHELL", "curl -fsS http://localhost:${APP_DOCKER_PORT}/health || exit 1"] - interval: 10s - timeout: 3s - retries: 10 - start_period: 20s - restart: unless-stopped - networks: - - suitecoffee-net + container_name: suitecoffee-app + depends_on: + suitecoffee-db: + condition: service_healthy + suitecoffee-tenants: + condition: service_healthy + build: + context: ./services/app + dockerfile: Dockerfile.development + volumes: + - ./services/app:/app + env_file: + - ./services/app/.env.development + environment: + - NODE_ENV=${NODE_ENV} + command: npm run dev + healthcheck: + # IMPORTANTE: asegurate de tener curl instalado en la imagen de app (ver nota abajo) + test: ["CMD-SHELL", "curl -fsS http://localhost:${APP_DOCKER_PORT}/health || exit 1"] + interval: 10s + timeout: 3s + retries: 10 + start_period: 20s + restart: unless-stopped + networks: + - suitecoffee-net suitecoffee-auth: container_name: suitecoffee-auth @@ -112,6 +116,8 @@ services: volumes: tenants-data: suitecoffee-data: + npm_data: + npm_letsencrypt: networks: suitecoffee-net: diff --git a/gateway/nginx.conf b/gateway/nginx.conf deleted file mode 100644 index 0d13c14..0000000 --- a/gateway/nginx.conf +++ /dev/null @@ -1,49 +0,0 @@ -worker_processes 1; - -events { worker_connections 1024; } - -http { - # Logs básicos - access_log /var/log/nginx/access.log; - error_log /var/log/nginx/error.log; - - # Ajustes útiles para proxys - proxy_http_version 1.1; - 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; - proxy_set_header Connection ""; - - # Soporte WebSocket (si lo usás en dev) - map $http_upgrade $connection_upgrade { - default upgrade; - '' close; - } - - server { - listen 80; - server_name _; - - # Frontend / App principal (Next/React/Express, etc.) - # / -> app - location / { - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - proxy_pass http://suitecoffee-app:4000; # usa el puerto interno de app - } - - # API de app (si preferís separar por path) - location /api/ { - proxy_pass http://suitecoffee-app:3000; - } - - # Servicio de autenticación (por ejemplo /auth/*) - # location /auth/ { - # proxy_pass http://suitecoffee-auth:4000; - # } - - # Opcional: servir estáticos si la app build genera /public - # location /static/ { alias /usr/share/nginx/html/static/; } - } -} diff --git a/services/app/src/index.js b/services/app/src/index.js index 3c1814b..9371bd5 100644 --- a/services/app/src/index.js +++ b/services/app/src/index.js @@ -64,11 +64,8 @@ async function verificarConexion() { // === Servir páginas estáticas === -app.use('/pages', express.static(path.join(__dirname, 'pages'))); +app.use(express.static(path.join(__dirname, 'pages'))); - -// Rutas de conveniencia para abrir cada página rápido: -// (Opcional: puedes usar directamente /pages/roles.html, etc.) app.get('/roles', (req, res) => res.sendFile(path.join(__dirname, 'pages', 'roles.html'))); app.get('/usuarios', (req, res) => res.sendFile(path.join(__dirname, 'pages', 'usuarios.html'))); app.get('/categorias',(req, res) => res.sendFile(path.join(__dirname, 'pages', 'categorias.html'))); diff --git a/services/auth/src/index.js b/services/auth/src/index.js index 6e3847d..33eef1f 100644 --- a/services/auth/src/index.js +++ b/services/auth/src/index.js @@ -35,6 +35,7 @@ try { const app = express(); app.use(cors()); app.use(express.json()); +app.set('trust proxy', 1); // Configuración de conexión PostgreSQL @@ -65,7 +66,7 @@ async function verificarConexion() { // === Servir páginas estáticas === -app.use('/pages', express.static(path.join(__dirname, 'pages'))); +app.use('/auth', express.static(path.join(__dirname, 'pages'))); app.get('/planes', async (req, res) => { try { @@ -82,13 +83,12 @@ app.get('/planes', async (req, res) => { } }); -// Rutas de conveniencia para abrir cada página rápido: -// (Opcional: puedes usar directamente /pages/roles.html, etc.) -app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'pages', 'index.html'))); +// Ruta raíz +app.get('/', (req, res) => { + res.sendFile(path.join(__dirname, 'pages', 'index.html')); +}); - - -app.post('/registro', async (req, res) => { +app.post('/api/registro', async (req, res) => { const { nombre_empresa, rut, @@ -143,7 +143,7 @@ app.post('/registro', async (req, res) => { }); -app.post('/login', async (req, res) => { +app.post('/api/login', async (req, res) => { const { correo, clave_acceso } = req.body; try { diff --git a/services/auth/src/pages/index.html b/services/auth/src/pages/index.html index cdb5125..9fef017 100644 --- a/services/auth/src/pages/index.html +++ b/services/auth/src/pages/index.html @@ -96,7 +96,7 @@ } try { - const url = modoRegistro ? '/registro' : '/login'; + const url = modoRegistro ? '/api/registro' : '/api/login'; const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' },