upstream stork_server {
    server ${API_HOST}:${API_PORT};
}

server {
    listen       80;
    server_name  localhost;
    root   /usr/share/stork/www;
    index  index.html;

    location /api {
        proxy_pass http://stork_server;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_buffering off;
        proxy_set_header Accept-Encoding "";
    }

    location /metrics {
        proxy_pass http://stork_server;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_buffering off;
        proxy_set_header Accept-Encoding "";
    }

    location /swagger.json {
        proxy_pass http://stork_server;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_buffering off;
        proxy_set_header Accept-Encoding "";
    }

    location /stork-install-agent.sh {
        proxy_pass http://stork_server;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_buffering off;
        proxy_set_header Accept-Encoding "";
    }

    location /sse {
        proxy_pass http://stork_server;
        # tips from here: https://serverfault.com/questions/801628/for-server-sent-events-sse-what-nginx-proxy-configuration-is-appropriate
        proxy_buffering off;
        proxy_cache off;
        proxy_set_header Connection '';
        proxy_http_version 1.1;
        chunked_transfer_encoding off;
    }

    location / {
        try_files ${DOLLAR}uri ${DOLLAR}uri/ /index.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;
    }
}
