Cloudflare Workers
Run and deploy a hand-authored Cloudflare Worker (its own wrangler.toml/wrangler.jsonc + source) as part of your Aspire app.
builder.AddCloudflareEnvironment();
builder.AddCloudflareWorker("worker", "../MyWorker");await builder.addCloudflareEnvironment();await builder.addCloudflareWorker('worker', '../MyWorker');aspire run→ the Worker runs locally withwrangler dev(Cloudflare’s Miniflare runtime) — no Cloudflare account required. It appears in the Aspire dashboard like any other resource.aspire deploy→ the Worker is deployed withwrangler deploy.
When to use this vs. Containers
Section titled “When to use this vs. Containers”| Use | For |
|---|---|
AddCloudflareWorker |
A Worker you author in JavaScript/TypeScript, with its own wrangler config. |
PublishAsCloudflareContainer |
A .NET project you want to run as a container (a Worker + Durable Object shim is generated for you). |
Options
Section titled “Options”builder.AddCloudflareWorker("worker", "../MyWorker", options =>{ options.Port = 8787; // the local `wrangler dev` port during `aspire run`});await builder.addCloudflareWorker('worker', '../MyWorker', { configure: async options => { await options.port.set(8787); }});Bindings, routes & custom domains
Section titled “Bindings, routes & custom domains”A hand-authored Worker owns its configuration, so add R2/KV/D1 bindings, routes and custom domains in the Worker’s own wrangler.jsonc — that’s the idiomatic place for them and it keeps wrangler dev and wrangler deploy in agreement. For example:
{ "name": "my-worker", "main": "src/index.js", "compatibility_date": "2025-06-01", "r2_buckets": [{ "binding": "UPLOADS", "bucket_name": "uploads" }], "routes": [{ "pattern": "api.example.com/*", "zone_id": "<ZONE_ID>" }]}Requirements
Section titled “Requirements”- wrangler and Node.js installed — see How wrangler authenticates.
- For deploy: an API token with Workers Scripts: Edit — see API Tokens.
- Local
wrangler devneeds no Cloudflare credentials.
