Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/workers-for-platforms/configuration.md
1# Configuration23## Dispatch Namespace Binding45### wrangler.jsonc6```jsonc7{8"$schema": "./node_modules/wrangler/config-schema.json",9"dispatch_namespaces": [{10"binding": "DISPATCHER",11"namespace": "production"12}]13}14```1516## Worker Isolation Mode1718Workers in a namespace run in **untrusted mode** by default for security:19- No access to `request.cf` object20- Isolated cache per Worker (no shared cache)21- `caches.default` disabled2223### Enable Trusted Mode2425For internal platforms where you control all code:2627```bash28curl -X PUT \29"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/dispatch/namespaces/$NAMESPACE" \30-H "Authorization: Bearer $API_TOKEN" \31-d '{"name": "'$NAMESPACE'", "trusted_workers": true}'32```3334**Caveats:**35- Workers share cache within namespace (use cache key prefixes: `customer-${id}:${key}`)36- `request.cf` object accessible37- Redeploy existing Workers after enabling trusted mode3839**When to use:** Internal platforms, A/B testing platforms, need geolocation data404142### With Outbound Worker43```jsonc44{45"dispatch_namespaces": [{46"binding": "DISPATCHER",47"namespace": "production",48"outbound": {49"service": "outbound-worker",50"parameters": ["customer_context"]51}52}]53}54```5556## Wrangler Commands5758```bash59wrangler dispatch-namespace list60wrangler dispatch-namespace get production61wrangler dispatch-namespace create production62wrangler dispatch-namespace delete staging63wrangler dispatch-namespace rename old new64```6566## Custom Limits6768Set CPU time and subrequest limits per invocation:6970```typescript71const userWorker = env.DISPATCHER.get(72workerName,73{},74{75limits: {76cpuMs: 10, // Max CPU ms77subRequests: 5 // Max fetch() calls78}79}80);81```8283Handle limit violations:84```typescript85try {86return await userWorker.fetch(request);87} catch (e) {88if (e.message.includes("CPU time limit")) {89return new Response("CPU limit exceeded", { status: 429 });90}91throw e;92}93```9495## Static Assets9697Deploy HTML/CSS/images with Workers. See [api.md](./api.md#static-assets) for upload process.9899### Wrangler100```jsonc101{102"name": "customer-site",103"main": "./src/index.js",104"assets": {105"directory": "./public",106"binding": "ASSETS"107}108}109```110111```bash112npx wrangler deploy --name customer-site --dispatch-namespace production113```114115### Dashboard Deployment116117Alternative to CLI:1181191. Upload Worker file in dashboard1202. Add `--dispatch-namespace` flag: `wrangler deploy --dispatch-namespace production`1213. Or configure in wrangler.jsonc under `dispatch_namespaces`122123See [api.md](./api.md) for programmatic deployment via REST API or SDK.124125## Tags126127Organize/search Workers (max 8/script):128129```bash130# Set tags131curl -X PUT ".../tags" -d '["customer-123", "pro", "production"]'132133# Filter by tag134curl ".../scripts?tags=production%3Ayes"135136# Delete by tag137curl -X DELETE ".../scripts?tags=customer-123%3Ayes"138```139140Common patterns: `customer-123`, `free|pro|enterprise`, `production|staging`141142## Bindings143144**Supported binding types:** 29 total including KV, D1, R2, Durable Objects, Analytics Engine, Service, Assets, Queue, Vectorize, Hyperdrive, Workflow, AI, Browser, and more.145146Add via API metadata (see [api.md](./api.md#deploy-with-bindings)):147```json148{149"bindings": [150{"type": "kv_namespace", "name": "USER_KV", "namespace_id": "..."},151{"type": "r2_bucket", "name": "STORAGE", "bucket_name": "..."},152{"type": "d1", "name": "DB", "id": "..."}153]154}155```156157Preserve existing bindings:158```json159{160"bindings": [{"type": "r2_bucket", "name": "STORAGE", "bucket_name": "new"}],161"keep_bindings": ["kv_namespace", "d1"] // Preserves existing bindings of these types162}163```164165For complete binding type reference, see [bindings](../bindings/) documentation166167See [README.md](./README.md), [api.md](./api.md), [patterns.md](./patterns.md), [gotchas.md](./gotchas.md)168