Overview
Cloudflare Workers provides:- Global Edge Network - Deployed to 300+ cities worldwide
- Zero Cold Starts - Instant response times
- Auto-scaling - Handles any traffic volume
- Built-in Security - DDoS protection and WAF
- Generous Free Tier - 100,000 requests/day
Prerequisites
- Cloudflare account
- Wrangler CLI installed
- Node.js 18+ installed
Quick Deployment
Authenticate with Cloudflare
Login to your Cloudflare account via Wrangler:This opens a browser window for authentication.
https://rubeus.YOUR_SUBDOMAIN.workers.dev.
Configuration
Wrangler Configuration
The gateway includes awrangler.toml configuration file:
wrangler.toml
Environment Variables
Set environment variables using Wrangler:Deployment Environments
Deploy to different environments:Custom Domain
Add a custom domain to your Worker:Add domain in Cloudflare Dashboard
- Navigate to Workers & Pages
- Select your Worker
- Go to Settings → Triggers
- Click “Add Custom Domain”
Using Wrangler
Add domains via Wrangler:Development
Local Development
Run the gateway locally with Wrangler:http://localhost:8787.
Development with Node.js
For faster iteration during development:Bindings
KV Namespace
Add KV storage for caching:wrangler.toml
R2 Storage
Add R2 buckets for object storage:wrangler.toml
D1 Database
Add D1 for SQL storage:wrangler.toml
Monitoring and Logs
View Logs
Stream real-time logs:Analytics
View analytics in the Cloudflare dashboard:- Navigate to Workers & Pages
- Select your Worker
- View the Analytics tab
Enable Logpush
For production environments, enable Logpush inwrangler.toml:
Resource Limits
Free Tier
- 100,000 requests/day
- 10ms CPU time per request
- 128 MB memory
Paid Plans
- Unlimited requests ($0.50 per million)
- 50ms CPU time per request
- 128 MB memory
Best Practices
- Use KV for caching to reduce compute time
- Minimize external API calls
- Use streaming responses for large payloads
- Implement proper error handling
Deployment Strategies
Blue-Green Deployment
Deploy to a staging environment first:Gradual Rollout
Use Cloudflare Workers’ percentage-based routing for gradual rollouts:- Deploy new version with a different name
- Configure traffic splitting in the dashboard
- Gradually increase traffic to the new version
CI/CD Integration
GitHub Actions
Create.github/workflows/deploy.yml:
deploy.yml
GitLab CI
Create.gitlab-ci.yml:
.gitlab-ci.yml
Troubleshooting
Build Errors
If you encounter build errors:Authentication Issues
Re-authenticate with Wrangler:CPU Time Exceeded
Optimize your code or upgrade to a paid plan for longer CPU time limits.Next Steps
Cloudflare Workers Docs
Learn more about Cloudflare Workers
Configuration
Configure the gateway for your needs