real_ip_header X-Forwarded-For;
set_real_ip_from 10.0.0.0/8;

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;

client_max_body_size 50M;

# nimu.li — Redirect-Service
server {
    listen 80;
    server_name nimu.li *.nimu.li;

    access_log /var/log/nginx/nimu.li.access.log;
    error_log  /var/log/nginx/nimu.li.error.log;

    location / {
        proxy_pass         http://app:80;
        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 https;
        proxy_set_header   Upgrade           $http_upgrade;
        proxy_set_header   Connection        "upgrade";
        proxy_read_timeout 30s;
    }
}

# app.nimuli.com — Dashboard
server {
    listen 80 default_server;
    server_name app.nimuli.com _;

    access_log /var/log/nginx/app.nimuli.com.access.log;
    error_log  /var/log/nginx/app.nimuli.com.error.log;

    # Vite Dev-Server (npm run dev läuft auf Host-Port 5173)
    location ~ ^/(@vite|@id|@fs|node_modules|resources/(css|js)|__vite_ping|__open-in-editor) {
        proxy_pass         http://host.docker.internal:5173;
        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 https;
        proxy_set_header   Upgrade           $http_upgrade;
        proxy_set_header   Connection        "upgrade";
        proxy_read_timeout    86400s;
        proxy_send_timeout    86400s;
        proxy_connect_timeout 86400s;
        proxy_buffering       off;
    }

    # Vite HMR WebSocket
    location /vite-hmr {
        proxy_pass         http://host.docker.internal:5173/vite-hmr;
        proxy_http_version 1.1;
        proxy_set_header   Host              $host;
        proxy_set_header   Upgrade           $http_upgrade;
        proxy_set_header   Connection        "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 https;
        proxy_read_timeout 86400;
        proxy_send_timeout 86400;
    }

    # Static assets — 1y cache for hashed builds
    location ~* ^/build/ {
        proxy_pass         http://app:80;
        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 https;
        add_header         Cache-Control "public, max-age=31536000, immutable";
        expires            1y;
    }

    location / {
        proxy_pass         http://app:80;
        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 https;
        proxy_set_header   Upgrade           $http_upgrade;
        proxy_set_header   Connection        "upgrade";
        proxy_read_timeout 60s;
    }
}
