【问题标题】:How to configure ng serve proxy with Windows authentication *and HTTPS*如何使用 Windows 身份验证*和 HTTPS* 配置 ng serve 代理
【发布时间】:2020-11-16 17:38:33
【问题描述】:

我想将ng serve 与受Windows 身份验证 (NTLM) 保护的后端服务器一起使用。这与这些帖子(example 1example 2)中的情况几乎相同,只是通过 HTTPS 访问服务器。

当我尝试使用相同的建议解决方案(适用于 HTTP)时,我收到 404 错误(但当然可以通过此 URL 访问服务器,我可以直接使用它进行测试浏览器)。

const Agent = require("agentkeepalive");

module.exports = {
    '/api': {
        target: "https://my-server.example.com",
        secure: false,
        changeOrigin: true,
        agent: new Agent({
            maxSockets: 100,
            keepAlive: true,
            maxFreeSockets: 10,
            keepAliveMsecs: 100000,
            timeout: 6000000,
            keepAliveTimeout: 90000
        }),
        onProxyRes: proxyRes => {
            const key = "www-authenticate";
            proxyRes.headers[key] = proxyRes.headers[key] &&
                proxyRes.headers[key].split(",");
        }
    }
}

我们将不胜感激,包括一些诊断问题的方法。

更新:使用 logLevel = "debug" 我得到以下堆栈跟踪(我不明白,因为相同的代理配置适用于 HTTPS,如果不是用于 Windows 配置) :

TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
    at new ClientRequest (_http_client.js:119:11)
    at Object.request (https.js:289:10)
    at Array.stream (C:\myproject\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:126:74)      
    at ProxyServer.<anonymous> (C:\myproject\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at middleware (C:\myproject\node_modules\http-proxy-middleware\lib\index.js:46:13)
    at handle (C:\myproject\node_modules\webpack-dev-server\lib\Server.js:322:18)
    at app.use (C:\myproject\node_modules\webpack-dev-server\lib\Server.js:330:47)
    at Layer.handle_error (C:\myproject\node_modules\express\lib\router\layer.js:71:5)
    at trim_prefix (C:\myproject\node_modules\express\lib\router\index.js:315:13)
    at C:\myproject\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\myproject\node_modules\express\lib\router\index.js:335:12)
    at next (C:\myproject\node_modules\express\lib\router\index.js:275:10)
    at Layer.handle [as handle_request] (C:\myproject\node_modules\express\lib\router\layer.js:97:5)
    at trim_prefix (C:\myproject\node_modules\express\lib\router\index.js:317:13)
    at C:\myproject\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\myproject\node_modules\express\lib\router\index.js:335:12)

【问题讨论】:

    标签: angular-cli windows-authentication webpack-dev-server


    【解决方案1】:

    通常,当我经过几天的努力在 Stack Overflow 上发布问题时,我会在接下来的一个小时内自己找到解决方案...

    问题在于Agent 仅适用于 HTTP。对于HTTPS,我们必须使用HttpsAgent

    const HttpsAgent = require('agentkeepalive').HttpsAgent;
    
    module.exports = {
        '/api': {
            target: "https://my-server.example.com",
            secure: false,
            changeOrigin: true,
            agent: new HttpsAgent({
                maxSockets: 100,
                keepAlive: true,
                maxFreeSockets: 10,
                keepAliveMsecs: 100000,
                timeout: 6000000,
                keepAliveTimeout: 90000
            }),
            onProxyRes: proxyRes => {
                const key = "www-authenticate";
                proxyRes.headers[key] = proxyRes.headers[key] &&
                    proxyRes.headers[key].split(",");
            }
        }
    }
    

    【讨论】:

    • 谢谢。我希望我早点找到这个。
    猜你喜欢
    • 2020-09-02
    • 1970-01-01
    • 2011-06-30
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    相关资源
    最近更新 更多