Build a website builder platform where users can create and deploy websites with custom domains using Cloudflare Workers for Platforms.
One-click deploy not ready yet... use instructions below to deploy
git clone https://github.com/dinasaur404/workers-platform-template.git
cd workers-platform-template
npm installCreate a D1 database to store project data:
npx wrangler d1 create workers-platform-templateCopy the database ID and update wrangler.toml:
database_id = "your-database-id-here"Create a dispatch namespace for deploying user scripts:
npx wrangler dispatch-namespace create workers-platform-templateUpdate these values in wrangler.toml:
[vars]
DISPATCH_NAMESPACE_NAME = "workers-platform-template"
ACCOUNT_ID = "your-account-id" # From Cloudflare dashboard sidebarDispatch Token — Used to deploy user websites to your Workers for Platforms namespace:
- Go to Cloudflare API Tokens
- Create token with permissions:
Account:Workers Scripts:Edit - Set as secret:
echo "your-token" | wrangler secret put DISPATCH_NAMESPACE_API_TOKEN
Custom Hostnames Token (Optional) — Used to automatically setup SSL for user domains via Custom Hostnames:
- Create token with permissions:
Zone:Custom Hostnames:Edit+Zone:Zone:Read - Set as secret:
echo "your-token" | wrangler secret put CLOUDFLARE_API_TOKEN
npx wrangler deployVisit your worker URL and add /init to setup the database:
https://your-worker.workers.dev/init
If you want branded URLs like build.yoursite.com instead of your-worker.workers.dev:
Add to wrangler.toml:
[vars]
CUSTOM_DOMAIN = "yoursite.com"
CLOUDFLARE_ZONE_ID = "your-zone-id" # From domain overview page
routes = [
{ pattern = "*/*", zone_name = "yoursite.com" }
]build.yoursite.com→ Your worker*.yoursite.com→ Your worker (for user subdomains)
Your users can then connect their own domains which will automatically get SSL certificates via Cloudflare for SaaS Custom Hostnames.
Create .dev.vars file:
DISPATCH_NAMESPACE_API_TOKEN=your-dispatch-token
CLOUDFLARE_API_TOKEN=your-cloudflare-tokenRun locally:
npx wrangler dev --remote- Builder: Visit the root URL to create websites
- User Sites: Each project gets a subdomain like
projectname.yoursite.com - Custom Domains: Users can connect their own domains with automatic SSL via Custom Hostnames
- Multi-tenant: Each user's code runs in isolation using Workers for Platforms
Visit /admin to see all projects and debug issues.
IMPORTANT: The admin page exposes sensitive database and infrastructure information. For production deployments, protect it with Cloudflare Access:
-
Create Access Application:
- Go to Cloudflare Zero Trust dashboard → Access → Applications
- Create Self-hosted application
- Application domain:
yourdomain.com/admin*
-
Configure Access Policy:
- Policy name:
Admin Access - Action:
Allow - Include rule:
Emails→ Add your email address
- Policy name:
This ensures only authorized users can access admin functionality while keeping the rest of your platform public.
"Dispatch namespace not found": Check your API token has Workers Scripts:Edit permission and the namespace exists
"Custom domain not working": Verify your Custom Hostnames API token permissions and DNS records
Database errors: Visit /init to reset the database
Debug logs: Run npx wrangler tail to see real-time logs
This template is production-ready but add rate limiting and input validation for public use.