mirror of
https://github.com/hknsh/project-knedita.git
synced 2024-11-28 17:41:15 +00:00
fix: updated rate-limit middleware
This commit is contained in:
parent
f4fcb2218c
commit
8d345747c6
1 changed files with 5 additions and 6 deletions
|
@ -3,22 +3,21 @@ import RedisStore from 'rate-limit-redis'
|
||||||
import redis from 'clients/redis-client'
|
import redis from 'clients/redis-client'
|
||||||
import logger from 'helpers/logger'
|
import logger from 'helpers/logger'
|
||||||
|
|
||||||
let maxConnections
|
let skip: boolean
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
||||||
logger.info('Development environment detected. Rate limit is now disabled.')
|
logger.info('Development environment detected. Rate limit is now disabled.')
|
||||||
maxConnections = 0
|
skip = true
|
||||||
} else {
|
} else {
|
||||||
maxConnections = 5
|
skip = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const limiter = rateLimit({
|
const limiter = rateLimit({
|
||||||
windowMs: 1 * 60 * 1000, // 60 seconds
|
windowMs: 1 * 60 * 1000, // 60 seconds
|
||||||
max: maxConnections,
|
max: 5,
|
||||||
message: { error: 'Too many requests' },
|
message: { error: 'Too many requests' },
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
|
skip: (_req, _res) => skip,
|
||||||
// Store configuration
|
|
||||||
store: new RedisStore({
|
store: new RedisStore({
|
||||||
sendCommand: async (...args: string[]) => await redis.sendCommand(args),
|
sendCommand: async (...args: string[]) => await redis.sendCommand(args),
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue