# Segunda instancia (white-label) — frontend React + API Odoo en puerto 8070.
#
# Acceso LAN inmediato: http://192.168.10.114:8880
# Acceso publico: requiere agregar el hostname en el dashboard del tunel
# cloudflared (remotamente administrado, sin config local):
#   ingress: - hostname: clinica2.consultoria-as.com
#               service: http://localhost:80
server {
    listen 80;
    listen 8880;
    server_name clinica2.consultoria-as.com;

    # Frontend React (mismo build que SKEEN; el brand sale del API /brand)
    location / {
        root /var/www/clinica2-frontend;
        try_files $uri $uri/ /index.html;
        add_header Cache-Control "no-cache";
    }

    # Odoo API para el frontend
    location /api/odoo/ {
        proxy_pass http://127.0.0.1:8070/;
        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_read_timeout 120s;
    }

    # Backend Odoo (administracion directa, opcional)
    location /web/ {
        proxy_pass http://127.0.0.1:8070/web/;
        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_read_timeout 120s;
    }

    # Escenario B: la instancia 2 no tiene WhatsApp. Aunque el backend tenga
    # fallback a localhost:3000, aqui se corta la ruta: 403 fijo, sin excepciones.
    location /api/odoo/skeen/frontend/v1/wacrm/ {
        return 403;
    }
}
