使用 NTLM 身份验证的 ng serve --proxy-config 不起作用 [英] ng serve --proxy-config with NTLM authentication is not working

查看:24
本文介绍了使用 NTLM 身份验证的 ng serve --proxy-config 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取 angular cli 的内部网络服务器(webpack 使用 node-http-proxy 我认为) 与 NTLM 身份验证一起使用,但很短.

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.

我这样设置 webpack 代理:<代码>//在packages.json 中...脚本":{"start": "ng serve --proxy-config proxy.conf.json",...

I set up the webpack proxy like this: // in packages.json ... "scripts": { "start": "ng serve --proxy-config proxy.conf.json", ...

proxy.config.json 的内容是:<代码>{/srv":{"target": "http://localhost/access_form","logLevel": "调试","auth": "登录:通过"}}

The contents of proxy.config.json is: { "/srv": { "target": "http://localhost/access_form", "logLevel": "debug", "auth": "LOGIN:PASS" } }

我正在尝试向 JSON 选项对象添加一个 onProxyRes 函数,但这无法启动网络服务器.

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?

推荐答案

我能够通过使用以下作为我的 proxy.config.js 文件来实现这个工作,该文件可以传递给 angular-cli 工具像这样 ng serve --watch --proxy-config proxy.config.js:

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;

确保你安装了 agentkeepalive 包:

Make sure you install the agentkeepalive package:

npm install --save-dev agentkeepalive

可在以下位置找到更多信息:

Further information can be found at:

这篇关于使用 NTLM 身份验证的 ng serve --proxy-config 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆