feat: Add rate limting to API (#11783)
This commit is contained in:
1 parent
891a656449
commit
dc9a4f0dba
3 files changed
+25
-1
No files matched your search
@@ -7,7 +7,7 @@ import logger from "./logger";
|
||||
const log = logger.getChildLogger({ prefix: ["RateLimit"] });
|
||||
|
||||
export type RateLimitHelper = {
|
||||
rateLimitingType?: "core" | "forcedSlowMode" | "common";
|
||||
rateLimitingType?: "core" | "forcedSlowMode" | "common" | "api";
|
||||
identifier: string;
|
||||
};
|
||||
|
||||
@@ -69,6 +69,12 @@ export function rateLimiter() {
|
||||
prefix: "ratelimit:slowmode",
|
||||
limiter: Ratelimit.fixedWindow(1, "30s"),
|
||||
}),
|
||||
api: new Ratelimit({
|
||||
redis,
|
||||
analytics: true,
|
||||
prefix: "ratelimit:api",
|
||||
limiter: Ratelimit.fixedWindow(10, "60s"),
|
||||
}),
|
||||
};
|
||||
|
||||
async function rateLimit({ rateLimitingType = "core", identifier }: RateLimitHelper) {
|
||||
|
||||
Reference in new issue
Block a user