server {
  listen 80;
  server_name _;

  # Allow large uploads (e.g. videos)
  client_max_body_size 300m;

  root /usr/share/nginx/html;
  index index.html;

  # SPA routing (Vue Router history mode)
  location / {
    try_files $uri $uri/ /index.html;
  }

  # Reverse proxy to backend (strip /api prefix)
  location /api/ {
    proxy_pass http://backend:8080/;
    proxy_http_version 1.1;
    # Keep original Host (incl. port) so backend can generate correct absolute URLs
    proxy_set_header Host $http_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;
  }

  # Serve uploaded files via backend static route
  location /static/ {
    proxy_pass http://backend:8080/static/;
    proxy_http_version 1.1;
    proxy_set_header Host $http_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_buffering off;
  }
}
