...
|
...
|
@@ -10,12 +10,12 @@ const helpers = global.yoho.helpers; |
|
|
let ONE_DAY = 60 * 60 * 24;
|
|
|
const MAX_QPS = config.maxQps;
|
|
|
|
|
|
let pages = {
|
|
|
const PAGES = {
|
|
|
'/product/\\/pro_([\\d]+)_([\\d]+)\\/(.*)/': 5,
|
|
|
'/product/list/index': 5
|
|
|
};
|
|
|
|
|
|
let ip_white_list= [
|
|
|
const IP_WHITE_LIST = [
|
|
|
'106.38.38.146',
|
|
|
'218.94.75.58'
|
|
|
];
|
...
|
...
|
@@ -39,7 +39,10 @@ module.exports = (req, res, next) => { |
|
|
remoteIp = arr[0];
|
|
|
}
|
|
|
|
|
|
if (remoteIp && !_.get(req.app.locals, 'pc.sys.noLimiter') && _.indexOf(ip_white_list, remoteIp) < 0) { // 判断获取remoteIp成功,并且开关未关闭
|
|
|
if (remoteIp &&
|
|
|
!_.get(req.app.locals, 'pc.sys.noLimiter') &&
|
|
|
_.includes(IP_WHITE_LIST, remoteIp)) { // 判断获取remoteIp成功,并且开关未关闭
|
|
|
|
|
|
let key = `pc:limiter:${remoteIp}`;
|
|
|
|
|
|
res.on('render', function() {
|
...
|
...
|
@@ -51,7 +54,7 @@ module.exports = (req, res, next) => { |
|
|
}
|
|
|
|
|
|
let pageKey = urlJoin(appPath, route.toString()); // route may be a regexp
|
|
|
let pageIncr = pages[pageKey] || 0;
|
|
|
let pageIncr = PAGES[pageKey] || 0;
|
|
|
|
|
|
if (pageIncr > 0) {
|
|
|
cache.incrAsync(key, pageIncr);
|
...
|
...
|
@@ -79,7 +82,7 @@ module.exports = (req, res, next) => { |
|
|
|
|
|
cache.getAsync(key).then((result) => {
|
|
|
if (result && _.isNumber(result)) {
|
|
|
if (result > MAX_QPS) { // 判断 qps
|
|
|
if (result > MAX_QPS) { // 判断 qps
|
|
|
cache.touch(key, ONE_DAY);
|
|
|
logger.info('req limit', key);
|
|
|
return limiterPage();
|
...
|
...
|
|