Authored by 陈峰

risk exclude

... ... @@ -8,9 +8,15 @@ const userAgent = require('./rules/useragent2');
// const asynchronous = require('./rules/asynchronous');
// const fakerLimiter = require('./rules/faker-limit');
const captchaPolicy = require('./policies/captcha');
const pathWhiteList = require('./rules/path-white-list');
// const reporterPolicy = require('./policies/reporter');
const _excluded = (req) => {
return Boolean(
_.includes(pathWhiteList(), req.path)
);
};
const limiter = (rule, policy, context) => {
return rule(context, policy);
};
... ... @@ -18,9 +24,10 @@ const limiter = (rule, policy, context) => {
module.exports = (req, res, next) => {
const remoteIp = req.yoho.clientIp || '';
const enabled = !_.get(req.app.locals, 'wap.sys.noLimiter');
let excluded = _excluded(req);
// 开关为关或者未获取到remoteIp,放行
if (!enabled || !remoteIp) {
if (!enabled || !remoteIp || excluded) {
logger.debug(`request remote ip: ${remoteIp}; enabled: ${enabled}`);
return next();
}
... ...