From e09011d813e711631e433d6ada3c7c21d06f6b20 Mon Sep 17 00:00:00 2001 From: Ilia Shupta Date: Tue, 15 Mar 2022 13:44:43 +0800 Subject: [PATCH] Allow fully qualified redis url use in koa ratelimit store --- packages/server/src/api/routes/public/index.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/routes/public/index.ts b/packages/server/src/api/routes/public/index.ts index 800eae6101..59ab3e0a44 100644 --- a/packages/server/src/api/routes/public/index.ts +++ b/packages/server/src/api/routes/public/index.ts @@ -31,16 +31,23 @@ function getApiLimitPerSecond(): number { if (!env.isTest()) { const REDIS_OPTS = getRedisOptions() - RateLimit.defaultOptions({ - store: new Stores.Redis({ - // @ts-ignore + let options + if (REDIS_OPTS.redisProtocolUrl) { // fully qualified redis URL + options = { + url: REDIS_OPTS.redisProtocolUrl, + } + } else { + options = { socket: { host: REDIS_OPTS.host, port: REDIS_OPTS.port, }, password: REDIS_OPTS.opts.password, database: 1, - }), + } + } + RateLimit.defaultOptions({ + store: new Stores.Redis(options) }) } // rate limiting, allows for 2 requests per second