Clean up rate limiter
This commit is contained in:
parent
55ee84d2f3
commit
9520086bfe
|
@ -1,5 +1,7 @@
|
||||||
|
// This script is included to help us test the rate limiter.
|
||||||
|
|
||||||
const apiUrl = 'https://ubs.rtech.foundation/api/v1/info'; // Replace with your API URL
|
const apiUrl = 'https://ubs.rtech.foundation/api/v1/info'; // Replace with your API URL
|
||||||
const interval = 1000; // 1 second
|
const interval = 500; // 1 second
|
||||||
|
|
||||||
const callApi = async () => {
|
const callApi = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -17,7 +17,7 @@ const middleware = (req, res, next) => {
|
||||||
if (!global.rateLimitList[requestIp]) {
|
if (!global.rateLimitList[requestIp]) {
|
||||||
global.rateLimitList[requestIp] = { requests: 0, lastRequest: Date.now() };
|
global.rateLimitList[requestIp] = { requests: 0, lastRequest: Date.now() };
|
||||||
}
|
}
|
||||||
console.log(`IP made ${global.rateLimitList[requestIp].requests}/${maxRequests} requests in ${(Date.now() - global.rateLimitList[requestIp].lastRequest) / 1000}/${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()) {
|
if (global.rateLimitList[requestIp].lastRequest + timeWindow * 1000 < Date.now()) {
|
||||||
global.rateLimitList[requestIp] = { requests: 0, lastRequest: Date.now() };
|
global.rateLimitList[requestIp] = { requests: 0, lastRequest: Date.now() };
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue