server {
    listen 80;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For &proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto &scheme;
    proxy_set_header Host $http_host;

    proxy_redirect off;

    location / {
        proxy_pass ${FRONTEND_URI};

        location /login {
            proxy_pass ${LOGIN_SERVICE_URI};
        }

        location /logout {
            proxy_pass ${LOGIN_SERVICE_URI};
        }

        location /oauth2 {
            proxy_pass ${LOGIN_SERVICE_URI};
        }

        location /refresh-token {
            proxy_pass ${LOGIN_SERVICE_URI};
        }
    }

    location /api {
        rewrite ^/api/(.*) /$1 break;

        proxy_pass ${CORE_API_URI};

        proxy_set_header Authorization "Bearer $cookie_pefi_token";
        proxy_pass_header Authorization;

        location /api/enums/widget-types {
            rewrite ^/api/(.*) /$1 break;
            proxy_pass ${WIDGETS_API_URI};
        }

        location /api/enums/supported-conversions {
            rewrite ^/api/(.*) /$1 break;
            proxy_pass ${STATEMENTS_API_URI};
        }

        location /api/widgets {
            rewrite ^/api/(.*) /$1 break;
            proxy_pass ${WIDGETS_API_URI};
        }

        location /api/statements {
            rewrite ^/api/(.*) /$1 break;
            proxy_pass ${STATEMENTS_API_URI};
        }
    }
}