@wrcb/cb-common 1.0.122 → 1.0.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,12 +9,10 @@ const rate_limit_redis_1 = __importDefault(require("rate-limit-redis"));
|
|
|
9
9
|
const ioredis_1 = __importDefault(require("ioredis"));
|
|
10
10
|
const tooManyRequestsError_1 = require("../errors/tooManyRequestsError");
|
|
11
11
|
function createRateApiLimiter(options) {
|
|
12
|
-
const { errorMessage = 'Calma lá, são muitas requisições. Tente novamente mais tarde!', windowMinutes = 3, // 🕒
|
|
13
|
-
max = 5, // 🚫
|
|
14
|
-
prefix = 'rl:', // 🏷 Prefixo usado
|
|
15
|
-
redisHost,
|
|
16
|
-
redisPort // 🔌 Porta na qual o servidor Redis está escutando (geralmente 6379 por padrão).
|
|
17
|
-
} = options;
|
|
12
|
+
const { errorMessage = 'Calma lá, são muitas requisições. Tente novamente mais tarde!', windowMinutes = 3, // 🕒 Janela de tempo em minutos
|
|
13
|
+
max = 5, // 🚫 Máx. de requisições por IP
|
|
14
|
+
prefix = 'rl:', // 🏷 Prefixo usado nas chaves Redis
|
|
15
|
+
redisHost, redisPort } = options;
|
|
18
16
|
const redisClient = new ioredis_1.default({
|
|
19
17
|
host: redisHost,
|
|
20
18
|
port: redisPort
|
|
@@ -26,7 +24,7 @@ function createRateApiLimiter(options) {
|
|
|
26
24
|
legacyHeaders: false,
|
|
27
25
|
store: new rate_limit_redis_1.default({
|
|
28
26
|
prefix,
|
|
29
|
-
sendCommand: (command, args) => redisClient.call(command, args)
|
|
27
|
+
sendCommand: (command, args) => redisClient.call(command, Array.isArray(args) ? args : [args])
|
|
30
28
|
}),
|
|
31
29
|
handler: function handleRateLimitExceeded(req, res, next) {
|
|
32
30
|
next(new tooManyRequestsError_1.TooManyRequestsError(errorMessage));
|