fix: updated rate-limit middleware

This commit is contained in:
Hackntosh 2023-09-30 17:57:17 -03:00
parent f4fcb2218c
commit 8d345747c6

View file

@ -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),
}),