Skill v1.0.1
currentAutomated scan100/1003 files
version: "1.0.1" name: adynato-cloudflare description: Cloudflare Workers and Pages deployment for Adynato projects. Covers wrangler CLI, reading logs for debugging, KV/D1/R2 storage, environment variables, and common errors. Use when deploying to Cloudflare, debugging workers, or configuring edge functions.
Cloudflare Skill
Use this skill when deploying Adynato projects to Cloudflare Workers or Pages.
Wrangler CLI
Installation
npm install -g wrangler# Or use npxnpx wrangler <command>
Authentication
# Interactive login (opens browser)wrangler login# Check auth statuswrangler whoami# Use API token (CI/CD)export CLOUDFLARE_API_TOKEN="your-token"
Reading Logs for Debugging
Tail Live Logs
# Stream logs from productionwrangler tail# Stream logs from specific environmentwrangler tail --env staging# Filter by statuswrangler tail --status error# Filter by search termwrangler tail --search "user-123"# Filter by IPwrangler tail --ip 192.168.1.1# JSON output for parsingwrangler tail --format json
Log Output Format
GET https://example.com/api/users - Ok @ 1/17/2026, 10:30:00 AM(log) Processing request for user-123(error) Database connection failed
Adding Console Logs
// Workers log to wrangler tailexport default {async fetch(request: Request, env: Env): Promise<Response> {console.log('Request received:', request.url)console.log('Headers:', Object.fromEntries(request.headers))try {const result = await doSomething()console.log('Result:', JSON.stringify(result))return Response.json(result)} catch (error) {console.error('Error:', error.message, error.stack)return Response.json({ error: 'Internal error' }, { status: 500 })}}}
Debugging Tips
- Always log request context first
``typescript console.log([${request.method}] ${new URL(request.url).pathname}) ``
- Log before and after async operations
``typescript console.log('Fetching from KV...') const value = await env.MY_KV.get(key) console.log('KV result:', value ? 'found' : 'not found') ``
- Use structured logging
``typescript console.log(JSON.stringify({ type: 'request', path: url.pathname, method: request.method, timestamp: Date.now() })) ``
Deployment
Deploy Worker
# Deploy to productionwrangler deploy# Deploy to specific environmentwrangler deploy --env staging# Dry run (see what would be deployed)wrangler deploy --dry-run# Deploy specific scriptwrangler deploy src/worker.ts
Deploy Pages
# Deploy to Pageswrangler pages deploy ./dist# Deploy with specific projectwrangler pages deploy ./dist --project-name=my-site# Deploy to specific branchwrangler pages deploy ./dist --branch=preview
Configuration
wrangler.toml
name = "my-worker"main = "src/index.ts"compatibility_date = "2026-01-17"# Environment variables (non-secret)[vars]API_URL = "https://api.example.com"NODE_ENV = "production"# KV Namespaces[[kv_namespaces]]binding = "MY_KV"id = "abc123"# D1 Databases[[d1_databases]]binding = "DB"database_name = "my-database"database_id = "def456"# R2 Buckets[[r2_buckets]]binding = "BUCKET"bucket_name = "my-bucket"# Durable Objects[[durable_objects.bindings]]name = "MY_DO"class_name = "MyDurableObject"# Staging environment[env.staging]name = "my-worker-staging"vars = { API_URL = "https://staging-api.example.com" }[[env.staging.kv_namespaces]]binding = "MY_KV"id = "staging-kv-id"
Secrets
# Add secret (interactive)wrangler secret put MY_SECRET# Add secret from stdinecho "secret-value" | wrangler secret put MY_SECRET# Add to specific environmentwrangler secret put MY_SECRET --env staging# List secretswrangler secret list# Delete secretwrangler secret delete MY_SECRET
Common Errors
"No account id found"
Error: No account id found, quitting...
Fix: Add account_id to wrangler.toml or login:
wrangler login# orwrangler whoami # to verify auth
# wrangler.tomlaccount_id = "your-account-id"
"Worker not found"
Error: worker not found
Fix: Check worker name matches wrangler.toml:
# List all workerswrangler deployments list# Check wrangler.toml name field
"KV namespace not found"
Error: namespace not found
Fix: Create the namespace first:
# Create KV namespacewrangler kv:namespace create MY_KV# Use the returned id in wrangler.toml
"Script too large"
Error: Script startup exceeded CPU time limit
Fix:
- Bundle size limit is 10MB (25MB on paid)
- Check for large dependencies
- Use dynamic imports for rarely-used code
# Check bundle sizewrangler deploy --dry-run --outdir=./distls -la ./dist
"Binding not found"
Error: Cannot find binding "MY_KV"
Fix: Ensure binding is in wrangler.toml and matches code:
// Code expects env.MY_KVinterface Env {MY_KV: KVNamespace // Must match wrangler.toml binding}
KV Storage
# Create namespacewrangler kv:namespace create MY_KV# List namespaceswrangler kv:namespace list# Put valuewrangler kv:key put --binding=MY_KV "my-key" "my-value"# Get valuewrangler kv:key get --binding=MY_KV "my-key"# List keyswrangler kv:key list --binding=MY_KV# Delete keywrangler kv:key delete --binding=MY_KV "my-key"# Bulk uploadwrangler kv:bulk put --binding=MY_KV data.json
D1 Database
# Create databasewrangler d1 create my-database# Execute SQLwrangler d1 execute my-database --command="SELECT * FROM users"# Execute SQL filewrangler d1 execute my-database --file=./schema.sql# Export databasewrangler d1 export my-database --output=backup.sql# List databaseswrangler d1 list
R2 Storage
# Create bucketwrangler r2 bucket create my-bucket# List bucketswrangler r2 bucket list# Upload filewrangler r2 object put my-bucket/path/file.txt --file=./local-file.txt# Download filewrangler r2 object get my-bucket/path/file.txt# Delete filewrangler r2 object delete my-bucket/path/file.txt
Local Development
# Start local dev serverwrangler dev# Dev with specific portwrangler dev --port 8787# Dev with local mode (no network to Cloudflare)wrangler dev --local# Dev with specific environmentwrangler dev --env staging# Dev with live reloadwrangler dev --live-reload
CI/CD with GitHub Actions
name: Deploy to Cloudflareon:push:branches: [main]jobs:deploy:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Setup Nodeuses: actions/setup-node@v4with:node-version: '20'- name: Install dependenciesrun: npm ci- name: Deploy Workerrun: npx wrangler deployenv:CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Required Secrets
| Secret | Description | |
|---|---|---|
CLOUDFLARE_API_TOKEN | API token with Workers edit permission | |
CLOUDFLARE_ACCOUNT_ID | Optional, can be in wrangler.toml |
Debugging Checklist
When a worker fails:
- Check live logs
``bash wrangler tail --status error ``
- Check recent deployments
``bash wrangler deployments list ``
- Rollback if needed
``bash wrangler rollback ``
- Test locally
``bash wrangler dev ``
- Check bindings
``bash wrangler kv:namespace list wrangler d1 list wrangler r2 bucket list ``
- Verify secrets
``bash wrangler secret list ``