http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    # Use Docker's internal DNS so upstream IPs are re-resolved after restarts
    resolver 127.0.0.11 valid=10s;
    resolver_timeout 5s;

    server {
        listen 80;
        server_name _;

        location /api/ {
            set $backend_upstream http://backend:8000;
            proxy_pass $backend_upstream;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_cache_bypass $http_upgrade;
        }

        location / {
            set $frontend_upstream http://frontend:80;
            proxy_pass $frontend_upstream;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

events {
    worker_connections 1024;
}
