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-playground/configuration.md
1# Configuration23## Getting Started45Navigate to [workers.cloudflare.com/playground](https://workers.cloudflare.com/playground)67- **No account required** for testing8- **No CLI or local setup** needed9- Code executes in real Cloudflare Workers runtime10- Share code via URL (never expires)1112## Playground Constraints1314⚠️ **Important Limitations**1516| Constraint | Playground | Production Workers |17|------------|------------|-------------------|18| **Module Format** | ES modules only | ES modules or Service Worker |19| **TypeScript** | Not supported (JS only) | Supported via build step |20| **Bindings** | Not available | KV, D1, R2, Durable Objects, etc. |21| **wrangler.toml** | Not used | Required for config |22| **Environment Variables** | Not available | Full support |23| **Secrets** | Not available | Full support |24| **Custom Domains** | Not available | Full support |2526**Playground is for rapid prototyping only.** For production apps, use `wrangler` CLI.2728## Code Editor2930### Syntax Requirements3132Must export default object with `fetch` handler:3334```javascript35export default {36async fetch(request, env, ctx) {37return new Response('Hello World');38}39};40```4142**Key Points:**43- Must use ES modules (`export default`)44- `fetch` method receives `(request, env, ctx)`45- Must return `Response` object46- TypeScript not supported (use plain JavaScript)4748### Multi-Module Code4950Import from external URLs or inline modules:5152```javascript53// Import from CDN54import { Hono } from 'https://esm.sh/hono@3';5556// Or paste library code and import relatively57// (See patterns.md for multi-module examples)5859export default {60async fetch(request) {61const app = new Hono();62app.get('/', (c) => c.text('Hello'));63return app.fetch(request);64}65};66```6768## Preview Panel6970### Browser Tab7172Default interactive preview with address bar:73- Enter custom URL paths74- Automatic reload on code changes75- DevTools available (right-click → Inspect)7677### HTTP Test Panel7879Switch to **HTTP** tab for raw HTTP testing:80- Change HTTP method (GET, POST, PUT, DELETE, PATCH, etc.)81- Add/edit request headers82- Modify request body (JSON, form data, text)83- View response headers and body84- Test different content types8586Example HTTP test:87```88Method: POST89URL: /api/users90Headers:91Content-Type: application/json92Authorization: Bearer token12393Body:94{95"name": "Alice",96"email": "[email protected]"97}98```99100## Sharing Code101102**Copy Link** button generates shareable URL:103- Code embedded in URL fragment104- Links never expire105- No account required106- Can be bookmarked for later107108Example: `https://workers.cloudflare.com/playground#abc123...`109110## Deploying from Playground111112Click **Deploy** button to move code to production:1131141. **Log in** to Cloudflare account (creates free account if needed)1152. **Review** Worker name and code1163. **Deploy** to global network (takes ~30 seconds)1174. **Get URL**: Deployed to `<name>.workers.dev` subdomain1185. **Manage** from dashboard: add bindings, custom domains, analytics119120**After deploy:**121- Code runs on Cloudflare's global network (300+ cities)122- Can add KV, D1, R2, Durable Objects bindings123- Configure custom domains and routes124- View analytics and logs125- Set environment variables and secrets126127**Note:** Deployed Workers are production-ready but start on Free plan (100k requests/day).128129## Browser Compatibility130131| Browser | Status | Notes |132|---------|--------|-------|133| Chrome/Edge | ✅ Full support | Recommended |134| Firefox | ✅ Full support | Works well |135| Safari | ⚠️ Broken | Preview fails with "PreviewRequestFailed" |136137**Safari users:** Use Chrome, Firefox, or Edge for Workers Playground.138139## DevTools Integration1401411. **Open preview** in browser tab1422. **Right-click** → Inspect Element1433. **Console tab** shows Worker logs:144- `console.log()` output145- Uncaught errors146- Network requests (subrequests)147148**Note:** DevTools show client-side console, not Worker execution logs. For production logging, use Logpush or Tail Workers.149150## Limits in Playground151152Same as production Free plan:153154| Resource | Limit | Notes |155|----------|-------|-------|156| CPU time | 10ms | Per request |157| Memory | 128 MB | Per request |158| Script size | 1 MB | After compression |159| Subrequests | 50 | Outbound fetch calls |160| Request size | 100 MB | Incoming |161| Response size | Unlimited | Outgoing (streamed) |162163**Exceeding CPU time** throws error immediately. Optimize hot paths or upgrade to Paid plan (30s default, 5min max CPU).164