'Angular Proxy to .net Core backend works every other time

Running into some weird stuff.. Trying to hit my api from my angular app. Since We need to use windows authentication we need to setup a proxy.conf for angular so it can pass credentials correctly. Here is my proxy.conf.js:

    const agent = require('agentkeepalive');

    module.exports = {
        '/api': {
            target: 'http://localhost:44366',
            secure: false,
            agent: new agent({
                maxSockets: 100,
                keepAlive: true,
                maxFreeSockets: 10,
                keepAliveMsecs: 100000,
                timeout: 6000000,
                keepAliveTimeout: 90000,
            }),
            onProxyRes: proxyRes => {
                let key = 'www-authenticate';
                proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
            },
        },
    };

Getting these errors every other request: enter image description here

Without fail my first request succeeds but the following request fails with 502 every time. enter image description here

enter image description here

Has anyone ever seen something like this before?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source