RateLimitOptionsBuilder
Ce contenu n’est pas encore disponible dans votre langue.
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>'))Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RateLimitOptionsBuilder():
RateLimitOptionsBuilder
Returns
Section titled “Returns”RateLimitOptionsBuilder
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”build()
Section titled “build()”build():
Partial<T>
Defined in: src/util/OptionsBuilder.ts:51
Snapshot the set fields as an independent Partial<T> (own props only).
Returns
Section titled “Returns”Partial<T>
Inherited from
Section titled “Inherited from”withCache()
Section titled “withCache()”withCache(
cache):this
Defined in: src/http/cache/RateLimitOptions.ts:56
Backing cache. Should be a shared/distributed one (Redis) in prod.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”this
withKey()
Section titled “withKey()”withKey(
key):this
Defined in: src/http/cache/RateLimitOptions.ts:71
Identity function — typically derives from IP, user id, or API key.
Parameters
Section titled “Parameters”(request) => string | Promise<string>
Returns
Section titled “Returns”this
withKeyPrefix()
Section titled “withKeyPrefix()”withKeyPrefix(
keyPrefix):this
Defined in: src/http/cache/RateLimitOptions.ts:76
Cache-key namespace prepended to the user key. Default 'rl:'.
Parameters
Section titled “Parameters”keyPrefix
Section titled “keyPrefix”string
Returns
Section titled “Returns”this
withMax()
Section titled “withMax()”withMax(
max):this
Defined in: src/http/cache/RateLimitOptions.ts:66
Maximum requests allowed per window per key.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”this
withOnLimit()
Section titled “withOnLimit()”withOnLimit(
onLimit):this
Defined in: src/http/cache/RateLimitOptions.ts:81
Custom 429 response builder — full control over the limit response.
Parameters
Section titled “Parameters”onLimit
Section titled “onLimit”(context) => HttpResponse
Returns
Section titled “Returns”this
withWindowMs()
Section titled “withWindowMs()”withWindowMs(
windowMs):this
Defined in: src/http/cache/RateLimitOptions.ts:61
Length of the rolling window in milliseconds.
Parameters
Section titled “Parameters”windowMs
Section titled “windowMs”number
Returns
Section titled “Returns”this
create()
Section titled “create()”
staticcreate():RateLimitOptionsBuilder
Defined in: src/http/cache/RateLimitOptions.ts:51
Start a fresh builder. Equivalent to new RateLimitOptionsBuilder().
Returns
Section titled “Returns”RateLimitOptionsBuilder
