# static frontend + API reverse proxy + compression & caching
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
gzip on;
gzip_types text/html application/javascript application/json text/css;
gzip_min_length 1024;

server {
    listen 80;
    server_name _;

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

    # data packs: immutable-ish, cache hard (bump filenames on data updates)
    location /data/ {
        add_header Cache-Control "public, max-age=86400";
    }

    location / {
        try_files $uri /index.html;
        add_header Cache-Control "public, max-age=300";
    }

    # backend API
    location /api/ {
        proxy_pass http://api:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_read_timeout 30s;
        # basic rate limit for the public calc/search endpoints
        limit_req zone=api burst=20 nodelay;
    }
}
