WorkerRoute
Source:
src/Cloudflare/Workers/Route.ts
A Workers Route — a zone-level mapping from a URL pattern to a Worker script.
Routes are the classic way to serve a Worker on a zone hostname or
path. The matched hostname must resolve through Cloudflare’s proxy,
so pair the route with a proxied DNS record (an AAAA 100::
placeholder is the conventional choice when the Worker is the only
origin).
Safety: routes carry no ownership markers, and Cloudflare enforces
one route per pattern per zone. When there is no prior state, read
scans the zone for an existing route with the same pattern and
reports it as Unowned, so the engine refuses to take it over unless
--adopt (or adopt(true)) is set.
Routing a hostname to a Worker
Section titled “Routing a hostname to a Worker”const worker = yield* Cloudflare.Worker("Api", { main: "./src/api.ts",});
yield* Cloudflare.WorkerRoute("ApiRoute", { zoneId: zone.zoneId, pattern: "api.example.com/*", script: worker.workerName,});
// Workers only run on proxied hostnames — give the host an origin.yield* Cloudflare.DnsRecord("ApiPlaceholder", { zoneId: zone.zoneId, name: "api.example.com", type: "AAAA", content: "100::", proxied: true,});Disabling Workers on a path
Section titled “Disabling Workers on a path”// No `script` — matching requests bypass Workers entirely.yield* Cloudflare.WorkerRoute("AssetsBypass", { zoneId: zone.zoneId, pattern: "example.com/assets/*",});