map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
  listen 80;
  client_max_body_size 8m;

  # Next.js (web)
  location / {
    proxy_pass http://web:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
  }

  # HMR websocket (Next dev)
  location /_next/webpack-hmr {
    proxy_pass http://web:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
  }

  # API (FastAPI)
  location /api/ {
    client_max_body_size 32m;
    proxy_pass http://api:8000/;
    proxy_set_header Host $host;
  }
}
