server {
  listen 80;
  root /usr/share/nginx/html;
  index index.html;

  # Résolveur DNS interne Docker : force nginx à re-résoudre "api" à chaque
  # requête au lieu de mettre l'IP en cache au démarrage (sinon un redeploy
  # du service api laisse nginx pointer vers un conteneur mort -> 502/404).
  resolver 127.0.0.11 valid=10s;

  location /admin/api/ {
    set $upstream_api http://api:3000;
    proxy_pass $upstream_api;
    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;
  }

  location /admin/auth/ {
    set $upstream_api http://api:3000;
    proxy_pass $upstream_api;
    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;
  }

  location / {
    try_files $uri $uri/ /index.html;
  }
}
