server {
    # Listen on all.
    listen 0.0.0.0:8081;
    listen [::]:8081 ipv6only=on;

    server_tokens off;

    add_header X-Frame-Options sameorigin;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    # no-cache to revalidate resources before using cache, to pick up possibled updated changes
    # from this nginx server serving the react-app
    add_header Cache-Control "private, no-cache, must-revalidate" always;

    location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

    # nginx.start.sh will convert environment variables into a config file located in /etc/config/config.json when running the container.
    # This file is located here because the nginx.start.sh script does not have permissions to write to the main html directory and we don't want to give it permissions to write there.
    location /config/config.json {
        root /etc;
        default_type application/json;
    }

    location /whisker-backend/ {
        rewrite ^/whisker-backend/(.*)$ /$1 break;
        proxy_pass http://localhost:3002;
        proxy_buffering off;
        proxy_request_buffering off;
        proxy_cache off;

        proxy_http_version 1.1;
        proxy_set_header Connection "";

        # Timeout settings: effectively disable timeouts, we don't want to proxy interfering with the server or client
        # functionality (especially for streaming APIs).
        proxy_read_timeout 1d;
        proxy_send_timeout 1d;
        proxy_connect_timeout 1d;
        send_timeout 1d;
        keepalive_timeout 1d;
    }

    error_page 404 =200 /index.html;
    location = /40x.html {
    }

    # redirect server error pages to the static page /50x.html
    error_page 500 502 503 504  /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}
