我正在使用 John Papa 的 lite 服务器和 chimurai 的 HTTP 代理中间件作为开发服务器。问题出在我的会话 cookie 上,我无法保留来自真实服务器的会话 cookie。我看到了这个解决方案: https ://github.com/chimurai/http-proxy-middleware/issues/78
但我看不出与我的 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})
}
}
};
有人知道如何合并这两者吗?
更新:这是响应标头的一部分:
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 未定义 :(