From 8d345747c6aee475ed93e376b98ecdce165e65f0 Mon Sep 17 00:00:00 2001 From: CookieDasora Date: Sat, 30 Sep 2023 17:57:17 -0300 Subject: [PATCH] fix: updated rate-limit middleware --- src/middlewares/rate-limit.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/middlewares/rate-limit.ts b/src/middlewares/rate-limit.ts index 6e51285..f6be82f 100644 --- a/src/middlewares/rate-limit.ts +++ b/src/middlewares/rate-limit.ts @@ -3,22 +3,21 @@ import RedisStore from 'rate-limit-redis' import redis from 'clients/redis-client' import logger from 'helpers/logger' -let maxConnections +let skip: boolean if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') { logger.info('Development environment detected. Rate limit is now disabled.') - maxConnections = 0 + skip = true } else { - maxConnections = 5 + skip = false } const limiter = rateLimit({ windowMs: 1 * 60 * 1000, // 60 seconds - max: maxConnections, + max: 5, message: { error: 'Too many requests' }, legacyHeaders: false, - - // Store configuration + skip: (_req, _res) => skip, store: new RedisStore({ sendCommand: async (...args: string[]) => await redis.sendCommand(args), }),