...
|
...
|
@@ -45,6 +45,7 @@ module.exports = function(proxyRoute) { |
|
|
}
|
|
|
//删除提交内容长度,代理会改变长度
|
|
|
delete options.headers['content-length'];
|
|
|
delete options.headers["accept-encoding"];
|
|
|
//设置代理host
|
|
|
options.headers['host'] = config.url.replace('http://','');
|
|
|
if(!req.session.gray) {
|
...
|
...
|
@@ -56,13 +57,14 @@ module.exports = function(proxyRoute) { |
|
|
logger.log('info','grayroute: request options: %j',options,{});
|
|
|
|
|
|
//发起代理请求
|
|
|
if(req.is('html')) {
|
|
|
if(req.headers['accept'].indexOf('text/html')>-1) {
|
|
|
request(options,function(err,res,body) {
|
|
|
if(err) {
|
|
|
logger.log('error','grayroute: request error:',err);
|
|
|
ress.status(500).send('');
|
|
|
} else {
|
|
|
setGrayCookie(req,res);
|
|
|
var ContentType = res.caseless.get('Content-Type');
|
|
|
ress.append('Content-Type',ContentType);
|
|
|
ress.status(res.statusCode).send(body);
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -85,19 +87,4 @@ module.exports = function(proxyRoute) { |
|
|
next();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 灰度cookie设置
|
|
|
* @param {Object} req express request
|
|
|
* @param {Object} res request的响应
|
|
|
*/
|
|
|
function setGrayCookie(req,res) {
|
|
|
//cookie透传到老系统
|
|
|
var cookie = res.caseless.get('set-cookie');
|
|
|
//如果没有设置到session
|
|
|
if(cookie && cookie.length>0 && !req.session.gray) {
|
|
|
req.session.gray = cookie[0];
|
|
|
}
|
|
|
return cookie;
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|