@canmertinyo/rate-limit-express 1.1.3 → 1.1.4
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.
- package/dist/rate.limiter.js +7 -2
- package/package.json +1 -1
- package/src/rate.limiter.ts +6 -6
package/dist/rate.limiter.js
CHANGED
@@ -15,13 +15,18 @@ function rateLimiter(options = rate_limiter_options_interface_1.defaultOptions)
|
|
15
15
|
storage.createRateLimitRecord(record);
|
16
16
|
return next();
|
17
17
|
}
|
18
|
-
if (record.timestamp < startTime) {
|
18
|
+
else if (record.timestamp < startTime) {
|
19
19
|
storage.updateRateLimitRecord(record.key, currentTime, 1);
|
20
20
|
return next();
|
21
21
|
}
|
22
|
-
if (record.count < options.maxRequest) {
|
22
|
+
else if (record.count < options.maxRequest) {
|
23
23
|
storage.increment(ip);
|
24
24
|
return next();
|
25
25
|
}
|
26
|
+
else {
|
27
|
+
res
|
28
|
+
.status(420)
|
29
|
+
.json({ message: "Too many requests, please try again later." });
|
30
|
+
}
|
26
31
|
};
|
27
32
|
}
|
package/package.json
CHANGED
package/src/rate.limiter.ts
CHANGED
@@ -18,16 +18,16 @@ export function rateLimiter(options: RateLimiterOptions = defaultOptions) {
|
|
18
18
|
record = { count: 1, timestamp: currentTime, key: ip };
|
19
19
|
storage.createRateLimitRecord(record);
|
20
20
|
return next();
|
21
|
-
}
|
22
|
-
|
23
|
-
if (record.timestamp < startTime) {
|
21
|
+
} else if (record.timestamp < startTime) {
|
24
22
|
storage.updateRateLimitRecord(record.key, currentTime, 1);
|
25
23
|
return next();
|
26
|
-
}
|
27
|
-
|
28
|
-
if (record.count < options.maxRequest) {
|
24
|
+
} else if (record.count < options.maxRequest) {
|
29
25
|
storage.increment(ip);
|
30
26
|
return next();
|
27
|
+
} else {
|
28
|
+
res
|
29
|
+
.status(420)
|
30
|
+
.json({ message: "Too many requests, please try again later." });
|
31
31
|
}
|
32
32
|
};
|
33
33
|
}
|