...
|
...
|
@@ -10,6 +10,7 @@ const sender = global.yoho.apmSender; |
|
|
const config = global.yoho.config;
|
|
|
const hostname = require('os').hostname();
|
|
|
const routeEncode = require('./route-encode');
|
|
|
const pathWhiteList = require('./limiter/rules/path-white-list');
|
|
|
const _ = require('lodash');
|
|
|
const limiterIpTime = 3600;
|
|
|
|
...
|
...
|
@@ -100,31 +101,34 @@ exports.serverError = () => { |
|
|
if (err.code === 9999991 || err.code === 9999992) {
|
|
|
let remoteIp = req.yoho.clientIp;
|
|
|
|
|
|
const isHuman = await cache.getAsync(`${config.app}:limiter:api:ishuman:${remoteIp}`);
|
|
|
if (!_.includes(pathWhiteList(), req.path)) {
|
|
|
const isHuman = await cache.getAsync(`${config.app}:limiter:api:ishuman:${remoteIp}`);
|
|
|
|
|
|
if (!isHuman) {
|
|
|
if (remoteIp.indexOf(',') > 0) {
|
|
|
let arr = remoteIp.split(',');
|
|
|
if (!isHuman) {
|
|
|
if (remoteIp.indexOf(',') > 0) {
|
|
|
let arr = remoteIp.split(',');
|
|
|
|
|
|
remoteIp = arr[0];
|
|
|
}
|
|
|
cache.setAsync(`${config.app}:limiter:${remoteIp}`, 1, limiterIpTime);
|
|
|
|
|
|
let limitAPI = helpers.urlFormat('/3party/check', {refer: req.get('Referer') || ''});
|
|
|
let limitPage = helpers.urlFormat('/3party/check', {
|
|
|
refer: req.protocol + '://' + req.get('host') + req.originalUrl
|
|
|
});
|
|
|
remoteIp = arr[0];
|
|
|
}
|
|
|
cache.setAsync(`${config.app}:limiter:${remoteIp}`, 1, limiterIpTime);
|
|
|
|
|
|
req.session.apiLimitValidate = true;
|
|
|
if (req.xhr) {
|
|
|
return res.status(510).json({
|
|
|
code: err.code,
|
|
|
data: {refer: limitAPI}
|
|
|
let limitAPI = helpers.urlFormat('/3party/check', {refer: req.get('Referer') || ''});
|
|
|
let limitPage = helpers.urlFormat('/3party/check', {
|
|
|
refer: req.protocol + '://' + req.get('host') + req.originalUrl
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return res.redirect(limitPage);
|
|
|
req.session.apiLimitValidate = true;
|
|
|
if (req.xhr) {
|
|
|
return res.status(510).json({
|
|
|
code: err.code,
|
|
|
data: {refer: limitAPI}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return res.redirect(limitPage);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
errorCode = 510;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -132,7 +136,7 @@ exports.serverError = () => { |
|
|
if (req.xhr) {
|
|
|
return res.status(errorCode).json({
|
|
|
code: errorCode,
|
|
|
message: '服务器错误!'
|
|
|
message: err.message || `服务器${errorCode === 510 ? '繁忙' : '错误'}!`
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -143,7 +147,7 @@ exports.serverError = () => { |
|
|
module: 'common',
|
|
|
page: 'error',
|
|
|
err: err,
|
|
|
title: '服务器错误 | Yoho!Buy有货 | 潮流购物逛不停',
|
|
|
title: `服务器${errorCode === 510 ? '繁忙' : '错误'} | Yoho!Buy有货 | 潮流购物逛不停`,
|
|
|
headerData: result.headerData
|
|
|
});
|
|
|
};
|
...
|
...
|
|