aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRitesh Ghosh <[email protected]>2024-03-12 22:54:09 +0530
committerRitesh Ghosh <[email protected]>2024-03-12 22:54:09 +0530
commit870fae700b56cc20010296387e3d9cda8330560c (patch)
treec173c60c276c04f2f993ec4ce899f059071174ed /src
parentca368db57eebaba6c0bafda20e024b6db59371d2 (diff)
downloadaniwatch-api-870fae700b56cc20010296387e3d9cda8330560c.tar.xz
aniwatch-api-870fae700b56cc20010296387e3d9cda8330560c.zip
feat: add json rate limit response; replace `max` with `limit`
Diffstat (limited to 'src')
-rw-r--r--src/config/ratelimit.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/config/ratelimit.ts b/src/config/ratelimit.ts
index 75cb1f8..67edfd8 100644
--- a/src/config/ratelimit.ts
+++ b/src/config/ratelimit.ts
@@ -1,11 +1,17 @@
-import { rateLimit } from "express-rate-limit";
import { config } from "dotenv";
+import createHttpError from "http-errors";
+import { rateLimit } from "express-rate-limit";
+
config();
export const ratelimit = rateLimit({
windowMs: Number(process.env.WINDOWMS) || 30 * 60 * 1000,
- max: Number(process.env.MAX) || 70,
+ limit: Number(process.env.MAX) || 50,
legacyHeaders: true,
standardHeaders: "draft-7",
- message: "Too many API requests, try again later",
+ handler: function (_, __, next) {
+ next(
+ createHttpError.TooManyRequests("Too many API requests, try again later")
+ );
+ },
});