# Kerf App — nginx reverse-proxy + SPA static server
# Serves the Vite-built app and proxies /engine/* to the kerf-engine container.

server {
    listen 80;
    server_name _;

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

    # ── Gzip ──
    gzip on;
    gzip_types text/plain text/css application/javascript application/json image/svg+xml;
    gzip_min_length 256;

    # ── Proxy /engine/* to the engine container ──
    location /engine/ {
        proxy_pass         http://kerf-engine:8000;
        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;

        # Engine trace/simplify can take a while on large images
        proxy_read_timeout 120s;
        proxy_send_timeout 120s;

        # Allow large image uploads (engine accepts multipart)
        client_max_body_size 50m;
    }

    # ── SPA fallback — serve index.html for client-side routes ──
    location / {
        try_files $uri $uri/ /index.html;
    }

    # ── Static asset caching ──
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|otf|eot)$ {
        expires 7d;
        add_header Cache-Control "public, immutable";
        try_files $uri =404;
    }
}
