Workers - Automatic loopback bindings via ctx.exports
9mo ago
Source
CloudflareWorkers - Automatic loopback bindings via ctx.exportscloudflare.comThe ctx.exports API contains automatically-configured bindings corresponding to your Worker's top-level exports. For each top-level export extending WorkerEntrypoint , ctx.exports will contain a Service Binding by the same name, and for each export extending DurableObject (and for which storage has been configured via a migration ), ctx.exports will contain a Durable Object namespace binding . This means you no longer have to configure these bindings explicitly in wrangler.jsonc / wrangler.toml . Example: import { WorkerEntrypoint } from "cloudflare:workers" ; export class Greeter extends WorkerEntrypoint { greet ( name ) { return `Hello, ${ name } !` ; } } export default { async fetch ( request , env , ctx ) { let greeting = await ctx . exports . Greeter . greet ( "World" ) return new Response ( greeting ) ; } } At present, you must use the enable_ctx_exports compatibility flag to enable this API, though it will be on by default in the future. See the API reference for more information.
You might also wanna read
Cloudflare expands AI bot management tools with granular traffic controls for all customers
Cloudflare is celebrating the second "Content Independence Day" by expanding AI traffic management options for all website owners. Building
Workers - Simpler runtime types with @cloudflare/workers-types v5
Cloudflare·2d ago
AI Search - Manage AI Search sync jobs with Wrangler CLI
Cloudflare·3d ago
Workers - Work across multiple accounts with Wrangler auth profiles
Cloudflare·3d ago
Cache - Cache multiple versions of a URL with Vary
Cloudflare·3d ago
Cloudflare One - Hostname routing for Cloudflare Mesh
Cloudflare·3d ago

Comments
Sign in to join the conversation.
No comments yet. Be the first.