1
0
Fork 0
mirror of synced 2024-07-03 13:30:46 +12:00

Merge pull request #4906 from fivehealth/allow-redis-url

Allow fully qualified redis url use in koa ratelimit store
This commit is contained in:
Michael Drury 2022-03-15 10:48:14 +00:00 committed by GitHub
commit 3a0b6a3d3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,16 +31,23 @@ function getApiLimitPerSecond(): number {
if (!env.isTest()) { if (!env.isTest()) {
const REDIS_OPTS = getRedisOptions() const REDIS_OPTS = getRedisOptions()
RateLimit.defaultOptions({ let options
store: new Stores.Redis({ if (REDIS_OPTS.redisProtocolUrl) { // fully qualified redis URL
// @ts-ignore options = {
url: REDIS_OPTS.redisProtocolUrl,
}
} else {
options = {
socket: { socket: {
host: REDIS_OPTS.host, host: REDIS_OPTS.host,
port: REDIS_OPTS.port, port: REDIS_OPTS.port,
}, },
password: REDIS_OPTS.opts.password, password: REDIS_OPTS.opts.password,
database: 1, database: 1,
}), }
}
RateLimit.defaultOptions({
store: new Stores.Redis(options)
}) })
} }
// rate limiting, allows for 2 requests per second // rate limiting, allows for 2 requests per second