Skip to main content
zerotal

Documentation


Documentation / zerotal / index / ThrottleOptions

Interface: ThrottleOptions

Defined in: packages/core/src/middleware/ThrottleMiddleware.ts:13

Properties

maxAttempts

maxAttempts: number

Defined in: packages/core/src/middleware/ThrottleMiddleware.ts:15

Maximum number of requests allowed within the window.


windowSeconds?

optional windowSeconds?: number

Defined in: packages/core/src/middleware/ThrottleMiddleware.ts:17

Time window in seconds. Defaults to 60.


keyResolver?

optional keyResolver?: (ctx) => string

Defined in: packages/core/src/middleware/ThrottleMiddleware.ts:22

Custom key resolver — defaults to client IP address. Use this to rate-limit by user ID, API key, route, etc.

Parameters

ctx

HttpContext

Returns

string


trustedProxies?

optional trustedProxies?: number

Defined in: packages/core/src/middleware/ThrottleMiddleware.ts:38

Number of trusted reverse proxies in front of this server.

X-Forwarded-For is client-writable, so it is only consulted when you state how many proxies sit in front of the app — the count is what says which entry is not attacker-controlled. Without it the unspoofable socket address is used.

  • undefined (default) / 0 — no trusted proxy; key on the socket address
  • 1 — one trusted proxy; the client IP is the second-to-last XFF entry
  • n — the client IP is n entries from the right

Example

// Behind one load balancer:
ThrottleMiddleware.with({ maxAttempts: 60, trustedProxies: 1 })