Zum Inhalt springen
Deutsch

RateLimitOptionsBuilder

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Defined in: src/http/cache/RateLimitOptions.ts:49

Fluent builder for RateLimitOptionsType:

rateLimit(RateLimitOptions.create().withCache(cache).withWindowMs(60_000).withMax(100).withKey((request) => request.remoteAddress ?? '<anon>'))

new RateLimitOptionsBuilder(): RateLimitOptionsBuilder

RateLimitOptionsBuilder

OptionsBuilder.constructor

build(): Partial<T>

Defined in: src/util/OptionsBuilder.ts:51

Snapshot the set fields as an independent Partial<T> (own props only).

Partial<T>

OptionsBuilder.build


withCache(cache): this

Defined in: src/http/cache/RateLimitOptions.ts:56

Backing cache. Should be a shared/distributed one (Redis) in prod.

Cache

this


withKey(key): this

Defined in: src/http/cache/RateLimitOptions.ts:71

Identity function — typically derives from IP, user id, or API key.

(request) => string | Promise<string>

this


withKeyPrefix(keyPrefix): this

Defined in: src/http/cache/RateLimitOptions.ts:76

Cache-key namespace prepended to the user key. Default 'rl:'.

string

this


withMax(max): this

Defined in: src/http/cache/RateLimitOptions.ts:66

Maximum requests allowed per window per key.

number

this


withOnLimit(onLimit): this

Defined in: src/http/cache/RateLimitOptions.ts:81

Custom 429 response builder — full control over the limit response.

(context) => HttpResponse

this


withWindowMs(windowMs): this

Defined in: src/http/cache/RateLimitOptions.ts:61

Length of the rolling window in milliseconds.

number

this


static create(): RateLimitOptionsBuilder

Defined in: src/http/cache/RateLimitOptions.ts:51

Start a fresh builder. Equivalent to new RateLimitOptionsBuilder().

RateLimitOptionsBuilder