Authored by 沈志敏

merge

@@ -10,8 +10,9 @@ const captchaPolicy = require('./policies/captcha'); @@ -10,8 +10,9 @@ const captchaPolicy = require('./policies/captcha');
10 const reporterPolicy = require('./policies/reporter'); 10 const reporterPolicy = require('./policies/reporter');
11 11
12 const IP_WHITE_LIST = [ 12 const IP_WHITE_LIST = [
13 - // '106.38.38.146',  
14 - // '218.94.75.58' 13 + '106.38.38.146',
  14 + '218.94.75.58',
  15 + '218.94.75.50'
15 ]; 16 ];
16 17
17 const limiter = (rule, policy, context) => { 18 const limiter = (rule, policy, context) => {
@@ -19,13 +20,18 @@ const limiter = (rule, policy, context) => { @@ -19,13 +20,18 @@ const limiter = (rule, policy, context) => {
19 }; 20 };
20 21
21 module.exports = (req, res, next) => { 22 module.exports = (req, res, next) => {
22 - let remoteIp = req.get('X-Forwarded-For') || req.connection.remoteAddress;  
23 - logger.debug('request remote ip: ', remoteIp); 23 + let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || '';
24 24
25 if (remoteIp.indexOf(',') > 0) { 25 if (remoteIp.indexOf(',') > 0) {
26 let arr = remoteIp.split(','); 26 let arr = remoteIp.split(',');
27 27
28 - remoteIp = arr[0]; 28 + remoteIp = arr[arr.length - 1];
  29 + }
  30 +
  31 + remoteIp = _.trim(remoteIp);
  32 +
  33 + if (_.startsWith(remoteIp, '10.66.')) {
  34 + remoteIp = req.get('X-Real-IP');
29 } 35 }
30 36
31 const excluded = _.includes(IP_WHITE_LIST, remoteIp); 37 const excluded = _.includes(IP_WHITE_LIST, remoteIp);
@@ -22,6 +22,10 @@ module.exports = (req, res, next) => { @@ -22,6 +22,10 @@ module.exports = (req, res, next) => {
22 return next(); 22 return next();
23 } 23 }
24 24
  25 + if (res.statusCode == 403) {
  26 + return res.end();
  27 + }
  28 +
25 if (req.xhr) { 29 if (req.xhr) {
26 return res.json({ 30 return res.json({
27 code: 400, 31 code: 400,