【发布时间】:2016-12-21 09:01:37
【问题描述】:
我正在使用 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
更新2: 我认为我的配置应该是这样的:
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值是什么? -
我更新了我原来的帖子。这是会话 cookie:set-cookie:JSESSIONID=620083CD7AEB7A6CC5772AC800E673E3;路径=/appServer/webservice/jaxrs;安全
-
您能否提供正在向服务器 3003 端口触发的 RAW 请求?
-
我正在使用 create react 应用程序,当我使用代理中间件时,我只获得了部分身份验证令牌(大小减小),这有什么原因吗?
标签: javascript angular http-proxy browser-sync lite-server