feat: add json rate limit response; replace max with limit
This commit is contained in:
@@ -1,11 +1,17 @@
|
|||||||
import { rateLimit } from "express-rate-limit";
|
|
||||||
import { config } from "dotenv";
|
import { config } from "dotenv";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { rateLimit } from "express-rate-limit";
|
||||||
|
|
||||||
config();
|
config();
|
||||||
|
|
||||||
export const ratelimit = rateLimit({
|
export const ratelimit = rateLimit({
|
||||||
windowMs: Number(process.env.WINDOWMS) || 30 * 60 * 1000,
|
windowMs: Number(process.env.WINDOWMS) || 30 * 60 * 1000,
|
||||||
max: Number(process.env.MAX) || 70,
|
limit: Number(process.env.MAX) || 50,
|
||||||
legacyHeaders: true,
|
legacyHeaders: true,
|
||||||
standardHeaders: "draft-7",
|
standardHeaders: "draft-7",
|
||||||
message: "Too many API requests, try again later",
|
handler: function (_, __, next) {
|
||||||
|
next(
|
||||||
|
createHttpError.TooManyRequests("Too many API requests, try again later")
|
||||||
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user