Files
poli0981andClaude Opus 5.5 0cdc730461 feat(worker): site-wide rate limit with the branded 429 page (D32) (#49)
* feat(worker): site-wide rate limit with the branded 429 page (D32)
* docs: record how the rate-limit binding really counts (measured on the preview)

Every page, feed and data request runs the Worker first and spends one
unit of SITE_LIMITER (60 per 10 s per IPv4 or IPv6 /64); over it, the
built /errors/429 page (status 429, Retry-After 10, no-store) or JSON
under /api/. What a page loads stays asset-first. Fails open. Measured on
the preview: holds a client on one connection; many-connection floods are
for the zone rule (docs/16 §9.1). Privacy #rate-limit, LEGAL_VERSION
2026-10-26, suite v3.0, v1.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 06:16:14 +07:00

29 lines
1.1 KiB
TypeScript

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 (SkullMute)
/** A Workers Rate Limiting binding (`ratelimits` in wrangler.jsonc). */
export interface RateLimiter {
limit(options: { key: string }): Promise<{ success: boolean }>;
}
/**
* What the Worker receives (wrangler.jsonc). Typed by hand rather than with
* @cloudflare/workers-types: these members are all it uses, and the global
* runtime types would collide with the DOM lib the site compiles against.
*/
export interface Env {
/** The static site itself (`assets.binding`). */
ASSETS: { fetch(request: Request): Promise<Response> };
/** The site-wide limit (D32): every request that runs the Worker. Absent → no limit. */
SITE_LIMITER?: RateLimiter;
/** The stricter /api/verify limit (D25). Absent under a bare `wrangler dev`. */
VERIFY_LIMITER?: RateLimiter;
/**
* Turnstile secret key. A RUNTIME secret (`wrangler secret put
* TURNSTILE_SECRET` or the dashboard's Variables and Secrets) — a Workers
* Builds *build* variable is invisible here. Missing → 503, and the page
* fails open.
*/
TURNSTILE_SECRET?: string;
}