Showing
1 changed file
with
8 additions
and
1 deletions
@@ -8,9 +8,15 @@ const userAgent = require('./rules/useragent2'); | @@ -8,9 +8,15 @@ const userAgent = require('./rules/useragent2'); | ||
8 | // const asynchronous = require('./rules/asynchronous'); | 8 | // const asynchronous = require('./rules/asynchronous'); |
9 | // const fakerLimiter = require('./rules/faker-limit'); | 9 | // const fakerLimiter = require('./rules/faker-limit'); |
10 | const captchaPolicy = require('./policies/captcha'); | 10 | const captchaPolicy = require('./policies/captcha'); |
11 | +const pathWhiteList = require('./rules/path-white-list'); | ||
11 | 12 | ||
12 | // const reporterPolicy = require('./policies/reporter'); | 13 | // const reporterPolicy = require('./policies/reporter'); |
13 | 14 | ||
15 | +const _excluded = (req) => { | ||
16 | + return Boolean( | ||
17 | + _.includes(pathWhiteList(), req.path) | ||
18 | + ); | ||
19 | +}; | ||
14 | const limiter = (rule, policy, context) => { | 20 | const limiter = (rule, policy, context) => { |
15 | return rule(context, policy); | 21 | return rule(context, policy); |
16 | }; | 22 | }; |
@@ -18,9 +24,10 @@ const limiter = (rule, policy, context) => { | @@ -18,9 +24,10 @@ const limiter = (rule, policy, context) => { | ||
18 | module.exports = (req, res, next) => { | 24 | module.exports = (req, res, next) => { |
19 | const remoteIp = req.yoho.clientIp || ''; | 25 | const remoteIp = req.yoho.clientIp || ''; |
20 | const enabled = !_.get(req.app.locals, 'wap.sys.noLimiter'); | 26 | const enabled = !_.get(req.app.locals, 'wap.sys.noLimiter'); |
27 | + let excluded = _excluded(req); | ||
21 | 28 | ||
22 | // 开关为关或者未获取到remoteIp,放行 | 29 | // 开关为关或者未获取到remoteIp,放行 |
23 | - if (!enabled || !remoteIp) { | 30 | + if (!enabled || !remoteIp || excluded) { |
24 | logger.debug(`request remote ip: ${remoteIp}; enabled: ${enabled}`); | 31 | logger.debug(`request remote ip: ${remoteIp}; enabled: ${enabled}`); |
25 | return next(); | 32 | return next(); |
26 | } | 33 | } |
-
Please register or login to post a comment