# Rendered by the nginx image entrypoint (envsubst on ${API_UPSTREAM}).
server {
  listen 80;
  server_name _;
  root /usr/share/nginx/html;
  index index.html;

  gzip on;
  gzip_types text/plain text/css application/json application/javascript image/svg+xml;
  client_max_body_size 30m;

  location /healthz { return 200 'ok'; add_header Content-Type text/plain; }

  # API and swagger go to the NestJS service; keep the /api prefix.
  location /api/ {
    proxy_pass ${API_UPSTREAM};
    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;
  }

  # Hashed assets: cache hard. index.html: never cache (deploys must show up immediately).
  location /assets/ { add_header Cache-Control "public, max-age=31536000, immutable"; try_files $uri =404; }
  location / { add_header Cache-Control "no-cache"; try_files $uri /index.html; }
}
