...
|
...
|
@@ -15,6 +15,11 @@ let pages = { |
|
|
'/product/list/index': 5
|
|
|
};
|
|
|
|
|
|
let ip_white_list= [
|
|
|
'106.38.38.146',
|
|
|
'218.94.75.58'
|
|
|
];
|
|
|
|
|
|
function urlJoin(a, b) {
|
|
|
if (_.endsWith(a, '/') && _.startsWith(b, '/')) {
|
|
|
return a + b.substring(1, b.length);
|
...
|
...
|
@@ -34,7 +39,7 @@ module.exports = (req, res, next) => { |
|
|
remoteIp = arr[0];
|
|
|
}
|
|
|
|
|
|
if (remoteIp && !_.get(req.app.locals, 'pc.sys.noLimiter')) { // 判断获取remoteIp成功,并且开关未关闭
|
|
|
if (remoteIp && !_.get(req.app.locals, 'pc.sys.noLimiter') && _.indexOf(ip_white_list, remoteIp) < 0) { // 判断获取remoteIp成功,并且开关未关闭
|
|
|
let key = `pc:limiter:${remoteIp}`;
|
|
|
|
|
|
res.on('render', function() {
|
...
|
...
|
@@ -76,6 +81,7 @@ module.exports = (req, res, next) => { |
|
|
if (result && _.isNumber(result)) {
|
|
|
if (result > MAX_QPS) { // 判断 qps
|
|
|
cache.touch(key, ONE_DAY);
|
|
|
logger.info('req limit', key);
|
|
|
return limiterPage();
|
|
|
} else {
|
|
|
cache.incrAsync(key, 1); // qps + 1
|
...
|
...
|
|