server { listen 80; root /usr/share/nginx/html; index index.html; # Banner entry points — cross-origin script loads from customer # sites, so they need permissive CORS. Served from the web root # because the loader derives the bundle URL from its own origin # (see apps/banner/src/loader.ts). Declared before the SPA # fallback so nginx doesn't rewrite them to index.html when the # files aren't yet built in dev. location = /consent-loader.js { add_header Access-Control-Allow-Origin "*" always; add_header Access-Control-Allow-Methods "GET, OPTIONS" always; add_header Cache-Control "public, max-age=3600" always; try_files $uri =404; } location = /consent-bundle.js { add_header Access-Control-Allow-Origin "*" always; add_header Access-Control-Allow-Methods "GET, OPTIONS" always; add_header Cache-Control "public, max-age=3600" always; try_files $uri =404; } # SPA fallback — serve index.html for all other routes location / { try_files $uri $uri/ /index.html; } # Proxy API requests to the backend # Uses Docker's embedded DNS with a variable so nginx resolves at request # time rather than at startup — prevents crash if api is temporarily down. location /api/ { resolver 127.0.0.11 valid=10s; set $upstream http://api:8000; proxy_pass $upstream; 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; } # Cache static assets location /assets/ { expires 1y; add_header Cache-Control "public, immutable"; } }