我正在使用由John Papa提供的作爲開發服務器的chimurai 的HTTP代理中間件的lite服務器。 問題出在我的會話cookie上,我無法堅持來自真實服務器的會話cookie。 我看到這個解決方案: https://github.com/chimurai/http-proxy-middleware/issues/78http-proxy-middleware,如何複製所有/ cookie標頭
,但我看不出有什麼相似之處我BS-config.js:
var proxy = require('http-proxy-middleware');
module.exports = {
port: 3003,
server: {
middleware: {
1: proxy('demo/webservice/jaxrs', {
target: 'https://localhost:8443',
secure: false, // disable SSL verification
changeOrigin: true // for vhosted sites, changes host header to match to target's host
}),
2: require('connect-history-api-fallback')({index: '/index.html', verbose: true})
}
}
};
是否有人知道如何合併這兩?
UPDATE:這是響應頭的一部分:
set-cookie:JSESSIONID=620083CD7AEB7A6CC5772AC800E673E3; Path=/appServer/webservice/jaxrs; Secure
strict-transport-security:max-age=31622400; includeSubDomains
Transfer-Encoding:chunked
UPDATE2: 我想我的配置應該是這樣的:
var proxy = require('http-proxy-middleware');
function relayRequestHeaders(proxyReq, req) {
Object.keys(req.headers).forEach(function (key) {
proxyReq.setHeader(key, req.headers[key]);
});
};
function relayResponseHeaders(proxyRes, req, res) {
Object.keys(proxyRes.headers).forEach(function (key) {
res.append(key, proxyRes.headers[key]);
});
};
module.exports = {
port: 3003,
server: {
middleware: {
1: proxy('/skybox', {
target: 'https://localhost:8443',
secure: false, // disable SSL verification
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
onProxyReq: relayRequestHeaders,
onProxyRes: relayResponseHeaders
}),
2: require('connect-history-api-fallback')({index: '/index.html', verbose: true})
}
}
};
但現在res.append未定義:(
你能提供來自目標的RAW迴應?該RAW響應中的「set-cookie」值是多少? – chimurai
我更新了我原來的帖子。這是會話cookie:set-cookie:JSESSIONID = 620083CD7AEB7A6CC5772AC800E673E3;路徑=/APPSERVER/web服務/ JAXRS;安全 – Avi
你還可以提供正在被激發到端口3003上的服務器的RAW請求嗎? – chimurai