Just goes to show, test locally
This commit is contained in:
parent
513c49106b
commit
718d601c5b
9
index.js
9
index.js
|
@ -344,6 +344,8 @@ setInterval(() => {
|
||||||
}, config.updateInterval * 1000);
|
}, config.updateInterval * 1000);
|
||||||
updateMasterList();
|
updateMasterList();
|
||||||
if (config.rateLimiterEnabled) {
|
if (config.rateLimiterEnabled) {
|
||||||
|
const rateLimiterWarnings = new Set();
|
||||||
|
|
||||||
app.use(rateLimit({
|
app.use(rateLimit({
|
||||||
windowMs: config.rateLimitWindow * 60 * 1000, // X minutes
|
windowMs: config.rateLimitWindow * 60 * 1000, // X minutes
|
||||||
max: config.rateLimitMax, // limit each IP to X requests per windowMs.
|
max: config.rateLimitMax, // limit each IP to X requests per windowMs.
|
||||||
|
@ -352,19 +354,22 @@ if (config.rateLimiterEnabled) {
|
||||||
},
|
},
|
||||||
skipFailedRequests: true,
|
skipFailedRequests: true,
|
||||||
handler: function (req, res /*, next*/ ) {
|
handler: function (req, res /*, next*/ ) {
|
||||||
|
const ip = config.behindProxy ? req.headers['x-real-ip'] : req.ip;
|
||||||
const remainingTime = Math.round((req.rateLimit.resetTime - Date.now()) / 1000);
|
const remainingTime = Math.round((req.rateLimit.resetTime - Date.now()) / 1000);
|
||||||
res.status(429).json({
|
res.status(429).json({
|
||||||
error: 'Too Many Requests',
|
error: 'Too Many Requests',
|
||||||
message: `You have exceeded the rate limit. Please try again in ${remainingTime} seconds.`,
|
message: `You have exceeded the rate limit. Please try again in ${remainingTime} seconds.`,
|
||||||
remainingTime: remainingTime
|
remainingTime: remainingTime
|
||||||
});
|
});
|
||||||
if (!req.rateLimit.remaining) {
|
if (req.rateLimit.remaining === 0 && !rateLimiterWarnings.has(ip)) {
|
||||||
console.log(`${colors.red(`[ERROR ${new Date()}]`)} ${req.headers["user-agent"]}@${config.behindProxy ? req.headers['x-real-ip'] : req.ip} exceeded rate limit!`);
|
rateLimiterWarnings.add(ip);
|
||||||
|
console.log(`${colors.red(`[ERROR ${new Date()}]`)} ${req.headers["user-agent"]}@${ip} exceeded rate limit!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
app.get('/check', (req, res) => {
|
app.get('/check', (req, res) => {
|
||||||
// Check that all required parameters are present
|
// Check that all required parameters are present
|
||||||
if (!req.query.address) {
|
if (!req.query.address) {
|
||||||
|
|
Loading…
Reference in a new issue