Skip to content
Snippets Groups Projects
Commit 75309009 authored by Xiao Gui's avatar Xiao Gui
Browse files

add support for redi username/password

parent d39a2a78
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,9 @@ const { ...@@ -16,6 +16,9 @@ const {
REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_ADDR, REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_ADDR,
REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_PORT, REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_PORT,
REDIS_USERNAME,
REDIS_PASSWORD,
HOSTNAME, HOSTNAME,
DISABLE_LIMITER, DISABLE_LIMITER,
} = process.env } = process.env
...@@ -24,12 +27,14 @@ const redisProto = REDIS_PROTO || REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP ...@@ -24,12 +27,14 @@ const redisProto = REDIS_PROTO || REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP
const redisAddr = REDIS_ADDR || REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_ADDR || null const redisAddr = REDIS_ADDR || REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_ADDR || null
const redisPort = REDIS_PORT || REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_PORT || 6379 const redisPort = REDIS_PORT || REDIS_RATE_LIMITING_DB_EPHEMERAL_PORT_6379_TCP_PORT || 6379
const redisURL = redisAddr && `${redisProto}://${redisAddr}:${redisPort}` const userPass = `${REDIS_USERNAME || ''}${( REDIS_PASSWORD && (':' + REDIS_PASSWORD)) || ''}${ (REDIS_USERNAME || REDIS_PASSWORD) && '@'}`
const redisURL = redisAddr && `${redisProto}://${userPass}${redisAddr}:${redisPort}`
const limiter = new RateLimit({ const limiter = new RateLimit({
windowMs: 1e3 * 5, windowMs: 1e3 * 5,
max: 5, max: 5,
// ...( redisURL ? { store: new RedisStore({ redisURL }) } : {} ) ...( redisURL ? { store: new RedisStore({ redisURL }) } : {} )
}) })
const passthrough = (_, __, next) => next() const passthrough = (_, __, next) => next()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment