ServerFnRateLimit
// Kept apart from rate-limit.ts so that defining a server function does not pull the limiter (and the address // parser it uses) into a bundle that only calls serverFn.
// Kept apart from rate-limit.ts so that defining a server function does not pull the limiter (and the address
// parser it uses) into a bundle that only calls serverFn.
/**
The rate limit of one server function, applied to every call that reaches the function over HTTP,
whether it came alone or inside a batch. Direct calls from server code (fn(), fn.invoke()) are
not network calls and are not charged.
Import#
ts
import type { ServerFnRateLimit } from "@shadow-js/dusk/server";
Signature#
ts
interface ServerFnRateLimit {
/** The limiter whose bucket is taken from. The bucket is per function and per caller. */
readonly limiter: RateLimiter;
/** The caller. Default: the client address (IPv6 by /64); requests without one share one bucket. */
readonly key?: (event: RequestEvent) => string | Promise<string>;
/** Tokens one call costs. Default 1. */
readonly cost?: number;
}
Members#
| Name | Type | Description |
|---|---|---|
limiter |
readonly limiter: RateLimiter |
The limiter whose bucket is taken from. The bucket is per function and per caller. |
key? |
readonly key?: (event: RequestEvent) => string | Promise<string> |
The caller. Default: the client address (IPv6 by /64); requests without one share one bucket. |
cost? |
readonly cost?: number |
Tokens one call costs. Default 1. |