From f69c1a73022ab7d742fff81be833d6e5cab989c7 Mon Sep 17 00:00:00 2001 From: Daniel Holmgren Date: Mon, 18 Sep 2023 14:19:20 -0500 Subject: [PATCH] Tweak rate limit setup for multi rate limit routes (#1627) tweak rate limit setup for multi rate limit routes --- packages/xrpc-server/src/server.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/xrpc-server/src/server.ts b/packages/xrpc-server/src/server.ts index 5d27e3e45a8..4e0a84ce4b7 100644 --- a/packages/xrpc-server/src/server.ts +++ b/packages/xrpc-server/src/server.ts @@ -405,7 +405,8 @@ export class Server { ? config.rateLimit : [config.rateLimit] this.routeRateLimiterFns[nsid] = [] - for (const limit of limits) { + for (let i = 0; i < limits.length; i++) { + const limit = limits[i] const { calcKey, calcPoints } = limit if (isShared(limit)) { const rateLimiter = this.sharedRateLimiters[limit.name] @@ -420,7 +421,7 @@ export class Server { } else { const { durationMs, points } = limit const rateLimiter = this.options.rateLimits?.creator({ - keyPrefix: nsid, + keyPrefix: `nsid-${i}`, durationMs, points, calcKey,