2

我試圖讓角度cli的內部網絡服務器(webpack使用node-http-proxy我認爲)與NTLM身份驗證一起工作並且不久。ng serve --proxy-config與NTLM身份驗證不起作用

我成立了這樣的的WebPack代理: // in packages.json ... "scripts": { "start": "ng serve --proxy-config proxy.conf.json", ...

proxy.config.json的內容是: { "/srv": { "target": "http://localhost/access_form", "logLevel": "debug", "auth": "LOGIN:PASS" } }

我想一個onProxyRes功能添加到JSON選項對象,但這不能啓動網絡服務器。

有沒有人有幸與此設置?任何指針?

回答

0

有一個在HTTP代理中間件的問題39解決部分問題,但它有一個問題:

var Agent = require('agentkeepalive'); 

{ 
    devServer: { 
    '/api/*': { 
     target: 'http://localhost:12121', 
     logLevel: 'debug', 
     agent: new Agent({ 
     maxSockets: 100, 
     keepAlive: true, 
     maxFreeSockets: 10, 
     keepAliveMsecs:1000, 
     timeout: 60000, 
     keepAliveTimeout: 30000 // free socket keepalive for 30 seconds 
    }), 
    onProxyRes: proxyRes => { 
     var key = 'www-authenticate'; 
     proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(','); 
     } 
    } 
    } 
} 

這裏的討論:https://github.com/chimurai/http-proxy-middleware/issues/39

一些用戶,包括我在內,越來越異常「TypeError:cb不是函數」。討論引用了一個nodejs/node問題:「保持活動模式下使用http.Agent的未捕獲TypeError#8650」,此時似乎尚未解決。

這裏的討論:https://github.com/nodejs/node/issues/8650

3

我能夠用得到這個工作以下爲我proxy.config.js文件可以傳遞到角CLI工具,像這樣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包:

npm install --save-dev agentkeepalive 

的更多信息,可以發現: