Skip to content

Commit 17bd421

Browse files
committed
chore: wip
1 parent 82e2c3a commit 17bd421

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

secure-registry/plugins/verdaccio-rate-limit-middleware/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import type {
66
} from '@verdaccio/types';
77

88
interface RateLimitConfig {
9-
redisUrl: string;
9+
// Optional in config; VERDACCIO_REDIS_URL env var takes precedence when set.
10+
redisUrl?: string;
1011
windowSeconds: number;
1112
maxRequests: number;
1213
}
@@ -42,7 +43,14 @@ class RateLimitMiddleware implements MiddlewarePlugin<any> {
4243
public constructor(private readonly config: RateLimitConfig, options: PluginOptions<any>) {
4344
this.logger = options.logger.child({ plugin: 'rate-limit-middleware' });
4445

45-
this.redisUrl = config.redisUrl;
46+
const envRedisUrl = process.env.VERDACCIO_REDIS_URL;
47+
this.redisUrl =
48+
(envRedisUrl && envRedisUrl.trim().length > 0
49+
? envRedisUrl
50+
: config.redisUrl && config.redisUrl.trim().length > 0
51+
? config.redisUrl
52+
: 'redis://redis:6379');
53+
4654
this.windowSeconds =
4755
typeof config.windowSeconds === 'number' && config.windowSeconds > 0
4856
? config.windowSeconds

secure-registry/verdaccio/lenient/config.docker.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ middlewares:
3535
timeoutMs: 60000
3636
policyId: "lenient"
3737
"@secure-registry/verdaccio-rate-limit-middleware":
38-
redisUrl: ${VERDACCIO_REDIS_URL:-redis://redis:6379}
38+
# Redis URL for rate limiting. VERDACCIO_REDIS_URL env var (if set)
39+
# takes precedence in the middleware implementation.
40+
redisUrl: "redis://redis:6379"
3941
windowSeconds: 86400 # 24h window
4042
maxRequests: 400 # 400 requests per 24h
4143

secure-registry/verdaccio/strict/config.docker.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ middlewares:
3737
timeoutMs: 60000
3838
policyId: "strict"
3939
"@secure-registry/verdaccio-rate-limit-middleware":
40-
redisUrl: ${VERDACCIO_REDIS_URL:-redis://redis:6379}
40+
# Redis URL for rate limiting. VERDACCIO_REDIS_URL env var (if set)
41+
# takes precedence in the middleware implementation.
42+
redisUrl: "redis://redis:6379"
4143
windowSeconds: 86400 # 24h window
4244
maxRequests: 400 # 400 requests per 24h
4345

0 commit comments

Comments
 (0)