# ==============================================================================
# Ring2All NMS — Neural Monitoring System Nginx Configuration
# ==============================================================================

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name _;
    add_header X-Robots-Tag "none" always;

    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_session_tickets off;

    root /var/www/ring2all-nms/web/dist;
    index index.html;

    client_max_body_size 50M;

    # ACME HTTP-01 challenge
    location ^~ /.well-known/acme-challenge/ {
        alias /var/www/ring2all-nms/web/dist/.well-known/acme-challenge/;
        default_type "text/plain";
    }

    # Frontend Single Page App routing
    location / {
        try_files $uri $uri/ /index.html;
    }

    # Static Assets (Logos, Icons, SVGs)
    location /assets/ {
        expires -1;
        add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
        add_header X-Robots-Tag "none" always;
    }

    # Backend API proxy
    location /api/ {
        proxy_pass http://127.0.0.1:3005;
        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;
        proxy_read_timeout 90s;
    }
}
