Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

Not translated yet

This page has not been translated into English yet, so it is shown in Spanish.

RateLimitOptions

interfaz Since 1.2.0

Límite de peticiones de un endpoint de API o un procedimiento RPC (desde 1.2): como mucho limit peticiones por ventana fija de window. Por encima, la respuesta es 429 RATE_LIMITED con Retry-After, antes de validar la entrada y de ejecutar el handler.

Sin key, cada IP de cliente tiene su contador (las IPv6 por su red /64) cuando Meeko la conoce: la de la conexión o, con MEEKO_TRUST_PROXY, la de X-Forwarded-For o la de CF-Connecting-IP (con cloudflare, desde 1.8), como clientAddress. Si no la conoce, todos los clientes comparten el contador de la ruta.

ts
import type { RateLimitOptions } from "@meekojs/meeko/server";

Source code src/server/runtime/rate-limit.ts:27

Declaración #

ts
interface RateLimitOptions<S = unknown> {
	readonly limit: number
	readonly window: number | string
	readonly key?: (context: RequestContext<S>) => string | Promise<string>
}

Type parameters #

S = unknown

Tipo de los servicios.

Example #

ts
import type { RateLimitOptions } from "@meekojs/meeko/server";

const login: RateLimitOptions = { limit: 5, window: "5m" };
const perUser: RateLimitOptions = { limit: 100, window: "1h", key: ({ session }) => String(session.current?.id ?? "anon") };

Propiedades #

limit #

propiedad sólo lectura

readonly limit: number

Peticiones permitidas en cada ventana; un entero positivo.

window #

propiedad sólo lectura

readonly window: number | string

Duración de la ventana: milisegundos o un texto como "30s", "5m", "1h" o "1d".

key #

propiedad sólo lectura opcional

readonly key?: (context: RequestContext<S>) => string | Promise<string>

Clave del contador dentro de la ruta, en lugar de la IP del cliente; por ejemplo, el usuario de la sesión. Se ejecuta antes de validar la entrada, así que no recibe el cuerpo.

See also #

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: packages/meeko/src/server/runtime/rate-limit.ts