Authored by 毕凯

clientIp

... ... @@ -412,7 +412,7 @@ function getRealIP(req) {
var realIP = req.headers['x-real-ip'];
var forwardedFor = req.headers['x-forwarded-for'] || '';
return realIP || forwardedFor.split(',')[0] || req.connection.remoteAddress;
return req.yoho.clientIp || forwardedFor.split(',')[0] || realIP || req.connection.remoteAddress;
}
const activateService = (req, res, next) => {
... ...
... ... @@ -53,19 +53,7 @@ const limiter = (rule, policy, context) => {
};
module.exports = (req, res, next) => {
let remoteIp = req.get('X-Yoho-Real-IP') || req.get('X-Forwarded-For') || req.get('X-Real-IP') || '';
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
remoteIp = arr[arr.length - 1];
}
if (_.startsWith(remoteIp, '10.66.')) {
remoteIp = req.get('X-Real-IP');
}
remoteIp = _.trim(remoteIp);
let remoteIp = req.yoho.clientIp || '';
// 排除条件:ip白名单/路径白名单/异步请求/登录用户
const excluded = _.includes(IP_WHITE_LIST, remoteIp) ||
... ...
... ... @@ -7,7 +7,6 @@
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const logger = global.yoho.logger;
const net = require('net');
/**
... ...