events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Add MIME type mapping for JavaScript modules
    types {
        application/javascript mjs;
    }

    # Gzip Settings
    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    server {
        listen 3000;
        server_name localhost;

        # Cache static assets with versioning (CSS, JS, fonts, images)
        # These files have cache-busting query parameters, so they can be cached aggressively
        location ~* \.(css|js|mjs|woff|woff2|ttf|eot|png|jpg|jpeg|gif|ico|svg|webp)$ {
            root /usr/share/nginx/html;
            expires 1y;
            add_header Cache-Control "public, immutable";
            try_files $uri =404;
        }

        # Never cache index.html and appsettings.json
        # These files must always be fresh to ensure users get the latest version
        location ~* ^/(index\.html|appsettings\.json)$ {
            root /usr/share/nginx/html;
            expires -1;
            add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
            add_header Pragma "no-cache";
            try_files $uri =404;
        }

        # Default location for all other files
        location / {
            root /usr/share/nginx/html;
            try_files $uri $uri/ /index.html =404;
        }
    }
}
