Add seconds since start to rate limit logging
This commit is contained in:
parent
212ba4ed94
commit
55ee84d2f3
|
@ -17,7 +17,7 @@ const middleware = (req, res, next) => {
|
|||
if (!global.rateLimitList[requestIp]) {
|
||||
global.rateLimitList[requestIp] = { requests: 0, lastRequest: Date.now() };
|
||||
}
|
||||
console.log(`Rate limit for ${requestIp}: ${global.rateLimitList[requestIp].requests}/${maxRequests} requests in the last ${timeWindow} seconds`);
|
||||
console.log(`IP made ${global.rateLimitList[requestIp].requests}/${maxRequests} requests in ${(Date.now() - global.rateLimitList[requestIp].lastRequest) / 1000}/${timeWindow} seconds.`);
|
||||
if (global.rateLimitList[requestIp].lastRequest + timeWindow * 1000 < Date.now()) {
|
||||
global.rateLimitList[requestIp] = { requests: 0, lastRequest: Date.now() };
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue