This commit is contained in:
Tom Moor
2022-08-16 19:43:50 +02:00
parent ed8176ca7d
commit 85dab03820
4 changed files with 12 additions and 13 deletions

View File

@@ -174,6 +174,6 @@ DEFAULT_LANGUAGE=en_US
# Optionally enable rate limiter at application web server
RATE_LIMITER_ENABLED=true
# Configure default throttling paramaters for rate limiter
RATE_LIMITER_REQUESTS=5000
# Configure default throttling parameters for rate limiter
RATE_LIMITER_REQUESTS=1000
RATE_LIMITER_DURATION_WINDOW=60

View File

@@ -13,6 +13,7 @@ export default class RateLimiter {
static readonly RATE_LIMITER_REDIS_KEY_PREFIX = "rl";
static readonly rateLimiterMap = new Map<string, RateLimiterRedis>();
static readonly defaultRateLimiter = new RateLimiterRedis({
storeClient: Redis.defaultClient,
points: env.RATE_LIMITER_REQUESTS,

View File

@@ -496,8 +496,7 @@ export class Environment {
);
/**
* A boolean switch to toggle the rate limiter
* at application web server.
* A boolean switch to toggle the rate limiter at application web server.
*/
@IsOptional()
@IsBoolean()
@@ -506,19 +505,18 @@ export class Environment {
);
/**
* Set max allowed requests in a given duration for
* default rate limiter to trigger throttling.
* Set max allowed requests in a given duration for default rate limiter to
* trigger throttling, per IP address.
*/
@IsOptional()
@IsNumber()
@CannotUseWithout("RATE_LIMITER_ENABLED")
public RATE_LIMITER_REQUESTS =
this.toOptionalNumber(process.env.RATE_LIMITER_REQUESTS) ?? 5000;
this.toOptionalNumber(process.env.RATE_LIMITER_REQUESTS) ?? 1000;
/**
* Set fixed duration window(in secs) for
* default rate limiter, elapsing which the request
* quota is reset(the bucket is refilled with tokens).
* Set fixed duration window(in secs) for default rate limiter, elapsing which
* the request quota is reset (the bucket is refilled with tokens).
*/
@IsOptional()
@IsNumber()

View File

@@ -7,9 +7,9 @@ import Metrics from "@server/logging/metrics";
import Redis from "@server/redis";
/**
* Middleware that limits the number of requests per IP address that are allowed
* within a window. Should only be applied once to a server do not use on
* individual routes.
* Middleware that limits the number of requests that are allowed within a given
* window. Should only be applied once to a server do not use on individual
* routes.
*
* @returns The middleware function.
*/