From 85dab03820c424b439a64d4d12ad76c0d2c745f4 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 16 Aug 2022 19:43:50 +0200 Subject: [PATCH] docs --- .env.sample | 4 ++-- server/RateLimiter.ts | 1 + server/env.ts | 14 ++++++-------- server/middlewares/rateLimiter.ts | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.env.sample b/.env.sample index 954ddd554..658a4d2ac 100644 --- a/.env.sample +++ b/.env.sample @@ -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 diff --git a/server/RateLimiter.ts b/server/RateLimiter.ts index 708cb4ebd..1c80d028a 100644 --- a/server/RateLimiter.ts +++ b/server/RateLimiter.ts @@ -13,6 +13,7 @@ export default class RateLimiter { static readonly RATE_LIMITER_REDIS_KEY_PREFIX = "rl"; static readonly rateLimiterMap = new Map(); + static readonly defaultRateLimiter = new RateLimiterRedis({ storeClient: Redis.defaultClient, points: env.RATE_LIMITER_REQUESTS, diff --git a/server/env.ts b/server/env.ts index 7a17e4f20..617b1f330 100644 --- a/server/env.ts +++ b/server/env.ts @@ -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() diff --git a/server/middlewares/rateLimiter.ts b/server/middlewares/rateLimiter.ts index f5d43e224..2a9f421cb 100644 --- a/server/middlewares/rateLimiter.ts +++ b/server/middlewares/rateLimiter.ts @@ -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. */