Files
youtube-generator/wrangler.jsonc
T
poli0981andClaude Opus 5.5 bdaf15d835 feat(worker): rate-limit every client before the gate
Two Workers Rate Limiting bindings in wrangler.jsonc, checked first in
the router so a flood costs no siteverify call, HMAC check or asset
fetch:

- RATE_LIMIT: 120 requests a minute for everything the Worker handles
  (gate page, app shell, legal pages, /__gate/*, any method).
- VERIFY_RATE_LIMIT: 10 a minute for POST /__gate/verify on top.

Clients are keyed by IPv4 address or IPv6 /64. Over the limit: 429 with
Retry-After: 60 (plain text, or JSON for the verify call). Like the
gate, it fails open when a binding is missing or limit() throws, and
logs that once per isolate. A test keeps wrangler.jsonc's bindings and
period in step with the code.

HOSTING documents both layers and the zone's WAF rate limiting rule
(Free plan: one rule, per IP, 10 s) as the first one.

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

83 lines
3.1 KiB
JSON

// Cloudflare Workers configuration for https://ytgenerator.stream.
//
// This is the only deployment file in the repo: Workers Builds (connected to
// this GitHub repository in the Cloudflare dashboard) runs `npx wrangler
// deploy` on every push to `main`, and `build.command` below produces `dist/`.
// There is no GitHub Actions deploy workflow. See docs/HOSTING.md.
{
"$schema": "node_modules/wrangler/config-schema.json",
// Must match the Worker the repository is connected to in the dashboard.
"name": "youtube-generator",
// The Turnstile gate + security headers in front of the static build.
"main": "worker/index.ts",
// Keep at or below the date the pinned wrangler's local runtime supports.
"compatibility_date": "2026-09-25",
// Serve the site only on the custom domain. `wrangler deploy` detaches any
// custom domain that is not listed here, so this entry is load-bearing.
"workers_dev": false,
"preview_urls": true,
"routes": [{ "pattern": "ytgenerator.stream", "custom_domain": true }],
"build": { "command": "npm run build" },
"assets": {
"directory": "./dist",
"binding": "ASSETS",
// NOT the SPA fallback: any path excluded from the Worker below would then
// get index.html without passing the gate. The Worker serves the app shell
// itself for gated routes; misses on public paths get dist/404.html.
"not_found_handling": "404-page",
// Everything goes through the Worker first, except content-hashed build
// output and the public files crawlers, browsers and the manifest fetch
// without cookies. Negative patterns win.
"run_worker_first": [
"/*",
"!/assets/*",
"!/icons/*",
"!/.well-known/*",
"!/favicon.svg",
"!/favicon.ico",
"!/apple-touch-icon.png",
"!/og-image.png",
"!/manifest.webmanifest",
"!/robots.txt",
"!/sitemap.xml",
"!/theme-init.js",
"!/licenses/*",
"!/404.html"
]
},
// Per-client rate limits (Workers Rate Limiting API): the second layer,
// behind the zone's WAF rate limiting rule — see docs/HOSTING.md. Counted
// per Cloudflare location, approximately, by IPv4 address or IPv6 /64.
// Over the limit → 429 with Retry-After. `period` may be 10 or 60 and must
// equal RATE_LIMIT_PERIOD_SECONDS in worker/env.ts; `namespace_id` is an
// integer (as a string) unique within the Cloudflare account.
"ratelimits": [
// Every request the Worker handles: the gate, the app shell, legal pages.
{
"name": "RATE_LIMIT",
"namespace_id": "1001",
"simple": { "limit": 120, "period": 60 }
},
// POST /__gate/verify on top of that — each one costs a siteverify call.
{
"name": "VERIFY_RATE_LIMIT",
"namespace_id": "1002",
"simple": { "limit": 10, "period": 60 }
}
],
"vars": {
// Public by design — the widget embeds it in the page. The matching
// secret is the dashboard Secret TURNSTILE_SECRET (never committed).
"TURNSTILE_SITE_KEY": "0x4AAAAAAFKFAMUx9rQ5H6bQ",
// How long a passed check lasts before the gate shows again.
"GATE_TTL_SECONDS": "86400"
},
"observability": { "enabled": true }
}