我想将ng serve
与带有Windows身份验证 (NTLM)保护的后端服务器一起使用。这与这些帖子(example 1、example 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(",");
}
}
}
任何帮助都将不胜感激,包括一些诊断问题的方法。
UPDATE:使用logLevel = "debug“,我得到了以下堆栈跟踪(我不理解这一点,因为如果不是Windows,相同的代理配置在HTTPS中工作得很好):
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)
发布于 2020-11-16 18:10:04
通常,当我在经过几天的挣扎之后,在Stack溢出上发布一个问题时,我会在接下来的一个小时内自己找到解决方案.
问题是,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(",");
}
}
}
https://stackoverflow.com/questions/64862939
复制相似问题