change ip from x-forward-for
Showing
4 changed files
with
14 additions
and
4 deletions
@@ -20,14 +20,17 @@ const limiter = (rule, policy, context) => { | @@ -20,14 +20,17 @@ const limiter = (rule, policy, context) => { | ||
20 | 20 | ||
21 | module.exports = (req, res, next) => { | 21 | module.exports = (req, res, next) => { |
22 | let remoteIp = req.get('X-Forwarded-For') || req.connection.remoteAddress; | 22 | let remoteIp = req.get('X-Forwarded-For') || req.connection.remoteAddress; |
23 | - logger.debug('request remote ip: ', remoteIp); | ||
24 | 23 | ||
25 | if (remoteIp.indexOf(',') > 0) { | 24 | if (remoteIp.indexOf(',') > 0) { |
26 | let arr = remoteIp.split(','); | 25 | let arr = remoteIp.split(','); |
27 | 26 | ||
28 | - remoteIp = arr[0]; | 27 | + remoteIp = arr[arr.length - 1]; |
29 | } | 28 | } |
30 | 29 | ||
30 | + remoteIp = _.trim(remoteIp); | ||
31 | + | ||
32 | + logger.info('request remote ip: ', remoteIp); | ||
33 | + | ||
31 | const excluded = _.includes(IP_WHITE_LIST, remoteIp); | 34 | const excluded = _.includes(IP_WHITE_LIST, remoteIp); |
32 | const enabled = !_.get(req.app.locals, 'wap.sys.noLimiter'); | 35 | const enabled = !_.get(req.app.locals, 'wap.sys.noLimiter'); |
33 | 36 |
@@ -20,6 +20,10 @@ module.exports = (req, res, next) => { | @@ -20,6 +20,10 @@ module.exports = (req, res, next) => { | ||
20 | return next(); | 20 | return next(); |
21 | } | 21 | } |
22 | 22 | ||
23 | + if (res.statusCode == 403) { | ||
24 | + return res.end(); | ||
25 | + } | ||
26 | + | ||
23 | if (req.xhr) { | 27 | if (req.xhr) { |
24 | return res.json({ | 28 | return res.json({ |
25 | code: 400, | 29 | code: 400, |
@@ -58,7 +58,10 @@ module.exports = (limiter, policy) => { | @@ -58,7 +58,10 @@ module.exports = (limiter, policy) => { | ||
58 | return Promise.resolve(true); | 58 | return Promise.resolve(true); |
59 | } | 59 | } |
60 | 60 | ||
61 | - if (result > MAX_QPS) { // 判断 qps | 61 | + if (result === 9999) { |
62 | + res.statusCode = 403; | ||
63 | + return Promise.resolve(policy); | ||
64 | + } else if (result > MAX_QPS) { // 判断 qps | ||
62 | cache.touch(key, ONE_DAY); | 65 | cache.touch(key, ONE_DAY); |
63 | logger.debug('req limit', key); | 66 | logger.debug('req limit', key); |
64 | 67 |
@@ -22,7 +22,7 @@ $(function() { | @@ -22,7 +22,7 @@ $(function() { | ||
22 | }, | 22 | }, |
23 | success: function(ret) { | 23 | success: function(ret) { |
24 | if (ret.code === 200) { | 24 | if (ret.code === 200) { |
25 | - window.location.href = decodeURIComponent(window.queryString.refer) || '//m.yohobuy.com'; | 25 | + window.location.href = window.queryString.refer ? decodeURIComponent(window.queryString.refer) : '//m.yohobuy.com'; |
26 | } else { | 26 | } else { |
27 | imgCheck.refresh(); | 27 | imgCheck.refresh(); |
28 | } | 28 | } |
-
Please register or login to post a comment