server {
    listen 8080;
    server_name localhost;
    root /usr/share/nginx/html;
    index index.html;

    # SPA fallback — serve index.html for all non-file routes
    location / {
        try_files $uri $uri/ /index.html;
    }

    # Cache static assets aggressively (hashed filenames)
    location /assets/ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # WASM files — correct MIME type + cache
    location /wasm/ {
        types { application/wasm wasm; }
        default_type application/javascript;
        expires 1y;
        add_header Cache-Control "public, immutable";
        add_header Cross-Origin-Embedder-Policy "require-corp";
        add_header Cross-Origin-Opener-Policy "same-origin";
    }

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