Function rateLimitRequest

  • Rate-limits a request by counting recent entries under a prefix in the RateLimit Durable Object, then either invokes the handler or the limit-reached response. Appends X-RateLimit-Limit / X-RateLimit-Remaining headers. A no-op passthrough to handlerFn when the RateLimit object is not registered.

    Parameters

    • prefix: string

      Namespace for the counter (e.g. "auth"), scoped per client.

    • params: RequestParams

      The request context, forwarded to handlerFn.

    • Optional handlerFn: Handler

      Handler to run when under the limit.

    • limit: number = REQUEST_LIMIT_AMOUNT_PER_HOUR

      Maximum requests allowed within timeLapse.

    • timeLapse: number = hourInMs

      Sliding window in milliseconds; defaults to one hour.

    • onLimitReached: any = ...

      Response factory used when the limit is exceeded; defaults to res_429.

    Returns Promise<any>

    The handler's response, or the limit-reached response.

Generated using TypeDoc