I'm trying to get angular cli's internal webserver (webpack uses node-http-proxy I think) to work with NTLM authentication and coming up short.
I set up the webpack proxy like this:
// in packages.json
...
"scripts": {
    "start": "ng serve --proxy-config proxy.conf.json",
...
The contents of proxy.config.json is:
{
  "/srv": {
    "target": "http://localhost/access_form",
    "logLevel": "debug",
    "auth": "LOGIN:PASS"
  }
}
I'm trying to add a onProxyRes function to the JSON options object but this fails to start the webserver.
Has anyone had any luck with this set up? Any pointers?
I was able to get this working by using the following as my proxy.config.js file that can be passed to the angular-cli tool like so ng serve --watch --proxy-config proxy.config.js:
var Agent = require("agentkeepalive");
var keepaliveAgent = new Agent({
    maxSockets: 100,
    keepAlive: true,
    maxFreeSockets: 10,
    keepAliveMsecs: 1000,
    timeout: 60000,
    keepAliveTimeout: 30000 // free socket keepalive for 30 seconds
});
var onProxyRes = function (proxyRes, req, res) {
    var key = 'www-authenticate';
    proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
};
const PROXY_CONFIG = [
    {
        target: "http://localhost:12345",
        context: "/api",
        secure: false,
        changeOrigin: true,
        auth: "LOGIN:PASS",
        loglevel: "debug",
        onProxyRes: onProxyRes,
        agent: keepaliveAgent
    }
];
module.exports = PROXY_CONFIG;
Make sure you install the agentkeepalive package:
npm install --save-dev agentkeepalive
Further information can be found at:
There is a partial solution in http-proxy-middleware issue 39, but it has an issue:
var Agent = require('agentkeepalive');
{
  devServer: {
    '/api/*': {
      target: 'http://localhost:12121',
      logLevel: 'debug',
      agent: new Agent({
        maxSockets: 100,
        keepAlive: true,
        maxFreeSockets: 10,
        keepAliveMsecs:1000,
        timeout: 60000,
        keepAliveTimeout: 30000 // free socket keepalive for 30 seconds
     }),
     onProxyRes: proxyRes => {
        var key = 'www-authenticate';
        proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
      }
    }
  }
}
Here's the discussion: https://github.com/chimurai/http-proxy-middleware/issues/39
Some users, including me, are getting the exception "TypeError: cb is not a function". The discussion references a nodejs/node issue: "Uncaught TypeError using http.Agent in keep-alive mode #8650" that appears to be unresolved at this time.
Here's the discussion: https://github.com/nodejs/node/issues/8650
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With