Skip to main content
Every experiment in this repository can be deployed independently to Cloudflare Workers. This guide covers all deployment methods and configuration steps.

Quick Deploy (Click-to-Deploy)

The fastest way to deploy any experiment is using Cloudflare’s one-click deployment:
1

Choose an experiment

Navigate to any experiment page and click the “Deploy to Cloudflare Workers” button.Each experiment README includes a deploy button linking to its source code.
2

Authenticate with Cloudflare

Sign in to your Cloudflare account or create one if you don’t have an account.The deployment system will request permissions to deploy Workers on your behalf.
3

Configure resources

Some experiments require additional resources:
  • D1 databases: Created automatically during deployment
  • KV namespaces: Created automatically
  • R2 buckets: Created automatically
  • Browser Rendering: Enabled automatically (requires plan upgrade)
  • Workers AI: Enabled automatically (requires plan upgrade)
The deployment wizard guides you through any required setup.
4

Deploy

Click the final deploy button. Your Worker will be deployed to a *.workers.dev subdomain.The deployment typically completes in 10-30 seconds.

Deployment URL Format

Click-to-deploy URLs follow this pattern:
https://deploy.workers.cloudflare.com/?url=https://github.com/{owner}/{repo}/tree/{branch}/experiments/{experiment-name}
Example:
https://deploy.workers.cloudflare.com/?url=https://github.com/shrinathsnayak/cloudflare-experiments/tree/main/experiments/ai-website-summary
To deploy from your own fork, replace shrinathsnayak with your GitHub username in the deployment URL.

Manual Deployment

For more control or local development, deploy manually using Wrangler CLI.
Install the required tools:
# Install Node.js 18+ (via nvm recommended)
nvm install 18
nvm use 18

# Install Wrangler CLI globally
npm install -g wrangler

# Authenticate with Cloudflare
wrangler login
Clone the repository:
git clone https://github.com/shrinathsnayak/cloudflare-experiments.git
cd cloudflare-experiments

Custom Domains

Add a custom domain to any deployed Worker:
1

Add domain to Cloudflare

Ensure your domain is already added to Cloudflare and using Cloudflare nameservers.
2

Navigate to Workers & Pages

In the Cloudflare dashboard:
  1. Go to Workers & Pages
  2. Select your deployed Worker
  3. Click the Triggers tab
3

Add custom domain

  1. Click Add Custom Domain
  2. Enter your subdomain (e.g., api.example.com)
  3. Click Add Custom Domain
Cloudflare automatically creates DNS records and provisions SSL certificates.

Environment Variables

Some experiments require environment variables. Set them in the dashboard or via Wrangler:
  1. Go to Workers & Pages
  2. Select your Worker
  3. Go to SettingsVariables
  4. Add variables (Plain text or Secret)
  5. Click Save

Deployment Checklist

1

Verify local functionality

npm run dev
# Test all endpoints
2

Check TypeScript

npm run build
# or: tsc --noEmit
3

Create required resources

  • D1 databases
  • KV namespaces
  • R2 buckets
  • Set environment variables
4

Run migrations (if applicable)

npm run db:migrate
5

Deploy

npm run deploy
6

Test production

curl https://your-worker.workers.dev

Troubleshooting

Deployment Fails

  • Authentication error: Run wrangler login to re-authenticate
  • Missing binding: Check wrangler.json for correct binding configuration
  • TypeScript errors: Run npm run build to identify issues

Runtime Errors

  • AI binding not found: Ensure Workers AI is enabled on your account
  • Browser binding not found: Enable Browser Rendering in your account
  • Database not found: Check D1 database_id in wrangler.json
  • KV not found: Check KV namespace id in wrangler.json
  • R2 not found: Verify bucket names in wrangler.json

Local Development Issues

  • AI doesn’t work locally: Use npm run dev -- --remote for Workers AI
  • Browser doesn’t work locally: Use npm run dev -- --remote for Browser Rendering
  • R2 public URLs don’t work: Use npm run dev -- --remote to test with real R2

Production Best Practices

Use Environment Variables

Store sensitive values as secrets, not in code:
wrangler secret put API_KEY

Set Rate Limits

Use Cloudflare’s Rate Limiting to prevent abuse:Configure in the Cloudflare dashboard under Security.

Monitor Usage

Track Worker invocations and errors:Workers & Pages → Your Worker → Metrics

Enable Analytics

Use Workers Analytics for detailed insights:Available on Workers Paid plan

Next Steps