使用NTLM身份验证的ng serve --proxy-config无法正常工作 [英] ng serve --proxy-config with NTLM authentication is not working

查看:104
本文介绍了使用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":"LOGIN:PASS"}}

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

我试图将onProxyRes函数添加到JSON选项对象,但这无法启动Web服务器.

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服务--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

更多信息,请访问:

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

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