webpack ng serve --proxy-config with NTLM authentication is not working

55ooxyrt  于 2023-10-19  发布在  Webpack
关注(0)|答案(2)|浏览(163)

我正试图让angular的内部web服务器(我认为webpack使用node-http-proxy)与NTLM身份验证一起工作,但没有成功。
我这样设置webpack代理:

  1. // in packages.json
  2. ...
  3. "scripts": {
  4. "start": "ng serve --proxy-config proxy.conf.json",
  5. ...

proxy.json.json的内容是:

  1. {
  2. "/srv": {
  3. "target": "http://localhost/access_form",
  4. "logLevel": "debug",
  5. "auth": "LOGIN:PASS"
  6. }
  7. }

我试图添加一个onProxyRes函数到JSON选项对象,但这无法启动Web服务器。
有没有人有任何运气与此设置?有什么建议吗?

sd2nnvve

sd2nnvve1#

我可以通过使用以下作为我的proxy.config.js文件来实现这一点,该文件可以传递给angular-tool,就像ng serve --watch --proxy-config proxy.config.js一样:

  1. var Agent = require("agentkeepalive");
  2. var keepaliveAgent = new Agent({
  3. maxSockets: 100,
  4. keepAlive: true,
  5. maxFreeSockets: 10,
  6. keepAliveMsecs: 1000,
  7. timeout: 60000,
  8. keepAliveTimeout: 30000 // free socket keepalive for 30 seconds
  9. });
  10. var onProxyRes = function (proxyRes, req, res) {
  11. var key = 'www-authenticate';
  12. proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
  13. };
  14. const PROXY_CONFIG = [
  15. {
  16. target: "http://localhost:12345",
  17. context: "/api",
  18. secure: false,
  19. changeOrigin: true,
  20. auth: "LOGIN:PASS",
  21. loglevel: "debug",
  22. onProxyRes: onProxyRes,
  23. agent: keepaliveAgent
  24. }
  25. ];
  26. module.exports = PROXY_CONFIG;

确保安装agentkeepalive包:

  1. npm install --save-dev agentkeepalive

更多信息请访问:

展开查看全部
kmpatx3s

kmpatx3s2#

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

  1. var Agent = require('agentkeepalive');
  2. {
  3. devServer: {
  4. '/api/*': {
  5. target: 'http://localhost:12121',
  6. logLevel: 'debug',
  7. agent: new Agent({
  8. maxSockets: 100,
  9. keepAlive: true,
  10. maxFreeSockets: 10,
  11. keepAliveMsecs:1000,
  12. timeout: 60000,
  13. keepAliveTimeout: 30000 // free socket keepalive for 30 seconds
  14. }),
  15. onProxyRes: proxyRes => {
  16. var key = 'www-authenticate';
  17. proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
  18. }
  19. }
  20. }
  21. }

讨论内容如下:https://github.com/chimurai/http-proxy-middleware/issues/39
包括我在内的一些用户会遇到异常“TypeError:cb不是函数”。讨论引用了一个nodejs/node问题:“Uncaught TypeError using http.Agent in keep-alive mode #8650”(在保持活动模式下使用http.Agent时未捕获类型错误#8650),此时似乎无法解决。
讨论内容如下:https://github.com/nodejs/node/issues/8650

展开查看全部

相关问题