events {
    worker_connections 1024;
}

http {
    # Enables log and error files
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Redirect HTTP to HTTPS
    server {
        listen 80;
        server_name spectral.ewi.tudelft.nl; # Update with your actual domain

        location / {
            return 301 https://$host$request_uri;
        }
    }

    # Defines the server listening on port 443 for HTTPS requests
    server {
        listen 443 ssl;
        server_name spectral.ewi.tudelft.nl; # Update with your actual domain

        ssl_certificate /certs/spectral_ewi_tudelft_nl.pem;
        ssl_certificate_key /certs/spectral_ewi_tudelft_nl.key;
        ssl_trusted_certificate /certs/spectral_ewi_tudelft_nl_interm.cer;

        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Configuration for the app service
        location / {
            proxy_pass http://app:5173; # Proxies requests to the app service
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            client_max_body_size 2G; # Allows file uploads up to 2G
        }

        # Configuration for the log service
        location ^~ /log/ {
            proxy_pass http://log:8080;

            chunked_transfer_encoding off;
            proxy_buffering off;
            proxy_cache off;
        }
    }
}
