Build a website builder platform where users can create and deploy websites with static assets and custom domains using Cloudflare Workers for Platforms.
✅ Visual Website Builder: User-friendly interface for creating websites
✅ Static Asset Upload: Upload HTML, CSS, images, and other static files
✅ Subdomain Routing: Automatic project.yourdomain.com routing
✅ Multi-tenant Isolation: Each project runs in its own isolated worker
✅ D1 Database: Fast project storage and management
✅ Real-time Deployment: Instant website deployment
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" # Get from Cloudflare dashboard sidebar
# Optional: For custom domain support, uncomment:
# BUILDER_DOMAIN = "build.yourdomain.com"
# APPS_DOMAIN = "yourdomain.com"Dispatch 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
This creates the projects table with fields for storing project data and static asset information.
If you want branded URLs like build.yourdomain.com instead of your-worker.workers.dev:
Uncomment and update in wrangler.toml:
[vars]
BUILDER_DOMAIN = "build.yourdomain.com" # Builder interface
APPS_DOMAIN = "yourdomain.com" # Base for *.yourdomain.com
# Also uncomment routes section:
routes = [
{ pattern = "build.yourdomain.com", zone_name = "yourdomain.com", custom_domain = true },
{ pattern = "*.yourdomain.com/*", zone_name = "yourdomain.com" }
]In your Cloudflare DNS dashboard:
build.yourdomain.com→ Your worker*.yourdomain.com→ Your worker (wildcard 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 with static assets
- Asset Upload: Upload folders of HTML, CSS, images, and other static files
- User Sites: Each project gets a subdomain like
projectname.yourdomain.com - Asset Serving: Static files are served via
env.ASSETSbinding with automatic caching - Custom Domains: Users can connect their own domains with automatic SSL
- Multi-tenant: Each user's code runs in isolation using Workers for Platforms
The platform supports uploading static assets using Cloudflare's Workers Assets API:
- Select a folder containing your static files (HTML, CSS, images, etc.)
- Files are uploaded and deployed with your worker
- Access assets via
env.ASSETS.fetch()in your worker code - Asset paths are stored in the database for reference
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 (WARNING: This deletes all projects)
Asset upload issues: Check that files are properly base64-encoded and manifest hashes match
Debug logs: Run npx wrangler tail to see real-time logs and deployment details
This project is licensed under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication.
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.