NG服务 - 带有NTLM身份验证的Proxy-Config不起作用



我正在尝试获取Angular CLI的内部Web服务器(WebPack使用node-http-proxy我认为)与NTLM身份验证一起工作并简短。

我设置了这样的WebPack代理:

// in packages.json
...
"scripts": {
    "start": "ng serve --proxy-config proxy.conf.json",
...

proxy.config.json的内容是:

{
  "/srv": {
    "target": "http://localhost/access_form",
    "logLevel": "debug",
    "auth": "LOGIN:PASS"
  }
}

我正在尝试将Onproxyres函数添加到JSON选项对象,但这未能启动Web服务器。

有人对此设置有任何运气吗?任何指针?

我能够通过将以下作为我的 proxy.config.js文件来使此功能运行,该文件可以传递给Angular-CLI工具,例如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;

确保安装代理保管包:

npm install --save-dev agentkeepalive

可以找到更多信息:

  • https://github.com/chimurai/http-proxy-middleware/issues/39
  • https://github.com/angular/angular/angular-cli/blob/4008768f8634c18bafd3c8e69e45f6464934934e9fe/docs/docs/documentation/documenta
  • https://github.com/nodejitsu/node-http-proxy/blob/master/examples/http/http/ntlm-authentication.js

http-proxy-middleware问题39中有部分解决方案,但它有一个问题:

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(',');
      }
    }
  }
}

以下是讨论:https://github.com/chimurai/http-proxy-middleware/issues/39

包括我在内的一些用户正在获得" TypeError:CB不是函数"的例外。讨论引用了一个nodejs/节点问题:"使用http.agent在保留模式#8650中使用的typeError"目前似乎尚未解决。

以下是讨论:https://github.com/nodejs/node/issues/8650

最新更新