...
|
...
|
@@ -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 forceNoCache = (res) => {
|
...
|
...
|
@@ -161,32 +162,34 @@ exports.serverError = () => { |
|
|
}));
|
|
|
}
|
|
|
} else if (err.code === 9999991 || err.code === 9999992) {
|
|
|
let remoteIp = req.yoho.clientIp;
|
|
|
if (!_.includes(pathWhiteList(), req.path)) {
|
|
|
let remoteIp = req.yoho.clientIp;
|
|
|
|
|
|
const isHuman = await cache.getAsync(`${config.app}:limiter:api:ishuman:${remoteIp}`);
|
|
|
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, config.LIMITER_IP_TIME);
|
|
|
|
|
|
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, config.LIMITER_IP_TIME);
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return _err510(req, res, 510, err);
|
...
|
...
|
|