在 Cloudflare Workers 上构建、部署和设计微型应用及网站。使用模板(React Router + Hono、Next.js、Astro、Remix)快速搭建、部署并配置...
Build and deploy micro apps and websites on Cloudflare Workers with production-grade design.
$0 ( create | deploy | domain | provision | secrets | status | teardown)$1 (template name, resource type, domain, etc.)$2, $3, etc.$ARGUMENTSCommandScriptExamplecreate``scripts/create-project.sh``/shellbot-website create my-app --template react-hono``deploy``scripts/deploy.sh``/shellbot-website deploy --env production``domain``scripts/setup-domain.sh``/shellbot-website domain my-worker example.com``provision``scripts/provision-*.sh``/shellbot-website provision d1 my-db``secrets``scripts/manage-secrets.sh``/shellbot-website secrets put API_KEY``status``scripts/status.sh``/shellbot-website status --resources``teardown``scripts/teardown.sh``/shellbot-website teardown my-worker
Two authentication methods, checked in this order:
Set CLOUDFLARE_API_TOKEN environment variable. This is the primary method — it takes precedence over OAuth if both are present.
If any command fails with authentication errors, tell user:
text
Get an API token from https://dash.cloudflare.com/profile/api-tokens
Use the "Edit Cloudflare Workers" template, or create a custom token with:
Workers Scripts: Edit
D1: Edit
Workers KV Storage: Edit
Workers R2 Storage: Edit
Zone DNS: Edit (for custom domains)
Then: export CLOUDFLARE_API_TOKEN="your-token-here"
wrangler login (fallback for local use)#If CLOUDFLARE_API_TOKEN is not set, attempt OAuth login:
bash
wrangler login
This opens a browser for Cloudflare OAuth. When running in an agent context:
wrangler login — it will print an authorization URL to stdoutlocalhost:8976~/.wrangler/config/default.tomlLimitation: This only works when the agent runs on the user's local machine (the OAuth callback must reach localhost:8976). It will NOT work in remote/CI environments — use API token there.
After login, verify with:
bash
wrangler whoami
All scripts check CLOUDFLARE_API_TOKEN first. If not set, they check if wrangler whoami succeeds (meaning OAuth tokens exist in ~/.wrangler/config/default.toml). If neither works, they error with instructions for both methods.
CLOUDFLARE_ACCOUNT_ID — auto-detected by wrangler. Set it to skip the account selection prompt when multiple accounts exist.
text
Find at: Dashboard → Overview → right sidebar → Account ID
Then: export CLOUDFLARE_ACCOUNT_ID="your-account-id"
npm install -g wrangler or use npx wranglerVerify setup:
bash
wrangler whoami
All scripts run fully non-interactively — no prompts, no user input required. This makes them safe for agent invocation. Destructive operations require explicit --force flags instead of confirmation prompts.
bash
# 1. Scaffold from template (fully non-interactive, no deploy, no git init)
bash scripts/create-project.sh my-app
# 2. Local development
cd my-app && npm run dev
# 3. Deploy to Cloudflare
bash scripts/deploy.sh
# 4. Add custom domain
bash scripts/setup-domain.sh my-app example.com
# 5. Provision resources as needed
bash scripts/provision-d1.sh my-db --binding DB
bash scripts/provision-kv.sh my-cache --binding CACHE
bash scripts/provision-r2.sh my-assets --binding ASSETS
Short NameTemplateBest Forreact-hono (default)react-router-hono-fullstack-templateFullstack apps with React Router 7 + Hono APInext``next-starter-templateNext.js apps on CF Workersbash
# Primary default (React Router + Hono)
bash scripts/create-project.sh my-app
# Use Next.js instead
bash scripts/create-project.sh my-app --template next
# Use any CF template by short name or full name
bash scripts/create-project.sh my-app --template astro-blog
bash scripts/create-project.sh my-app --template remix
bash scripts/create-project.sh my-app --template vite-react
See references/cf-templates.md for the full catalog of 36+ templates.
bash
bash scripts/create-project.sh my-app --template-url https://github.com/user/repo
bash
# Deploy to production
bash scripts/deploy.sh
# Deploy to specific environment
bash scripts/deploy.sh --env staging
bash scripts/deploy.sh --env production
# Dry run (shows what would deploy)
bash scripts/deploy.sh --dry-run
# View deployments
wrangler deployments list
# Rollback to previous version
wrangler rollback [version-id]
The deploy.sh script pre-checks that wrangler config exists and CLOUDFLARE_API_TOKEN is set before deploying.
Three approaches to connect a custom domain to a CF Worker. See references/custom-domains.md for the full guide.
bash
# Domain must already be in your CF account
bash scripts/setup-domain.sh my-worker example.com
# With specific zone ID (skips lookup)
bash scripts/setup-domain.sh my-worker example.com --zone-id abc123
# Subdomain
bash scripts/setup-domain.sh my-worker app.example.com
toml
[[routes]]
pattern = "example.com/*"
zone_id = "your-zone-id"
Workers & Pages → your worker → Settings → Domains & Routes → Add Custom Domain.
bash
bash scripts/provision-d1.sh my-db --binding DB
# Creates database, outputs binding snippet for wrangler.toml
# Optional: --migration-file schema.sql (applies initial migration)
Common D1 operations:
bash
wrangler d1 execute my-db --command "SELECT * FROM users"
wrangler d1 execute my-db --file schema.sql
wrangler d1 execute my-db --local --command "..." # Local dev
wrangler d1 migrations create my-db add-users
wrangler d1 migrations apply my-db
bash
bash scripts/provision-kv.sh my-cache --binding CACHE
# Creates namespace, outputs binding snippet
bash
bash scripts/provision-r2.sh my-assets --binding ASSETS
# Creates bucket, outputs binding snippet
bash
bash scripts/provision-queue.sh my-queue --binding QUEUE --type producer
# Creates queue, outputs producer/consumer binding snippets
bash
# Add a secret (non-interactive)
bash scripts/manage-secrets.sh put API_KEY "sk-..."
# List secrets
bash scripts/manage-secrets.sh list
# Delete a secret
bash scripts/manage-secrets.sh delete API_KEY
# Bulk upload from JSON
bash scripts/manage-secrets.sh bulk secrets.json
# Environment-specific
bash scripts/manage-secrets.sh put API_KEY "sk-..." --env production
Wrangler supports TOML and JSON/JSONC. If both exist, JSON takes precedence. Pick one.
toml
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-12-30"
compatibility_flags = ["nodejs_compat"]
[vars]
API_URL = "https://api.example.com"
[[d1_databases]]
binding = "DB"
database_name = "my-db"
database_id = "xxx"
[[kv_namespaces]]
binding = "CACHE"
id = "xxx"
[[r2_buckets]]
binding = "ASSETS"
bucket_name = "my-assets"
[env.production]
vars = { API_URL = "https://api.example.com" }
[env.staging]
vars = { API_URL = "https://staging-api.example.com" }
See references/wrangler-config.md for the full reference including JSONC format, static assets, and all binding types.
When building the frontend, apply these principles. Each links to a deep reference guide.
→ See references/typography.md
Choose distinctive fonts (not Inter/Roboto). Use a modular type scale with clamp() for headings. Pair a display font with a body font. Use font-display: swap and fallback metric matching to prevent layout shift.
→ See references/color-and-contrast.md
Use OKLCH for perceptually uniform palettes. Tint neutrals toward your brand hue. Follow the 60-30-10 rule (neutrals / secondary / accent). Avoid pure black/white. Avoid the AI palette (cyan-on-dark, purple-blue gradients).
→ See references/spatial-design.md
Use a 4pt spacing system. Create rhythm through varied spacing. Use auto-fit grids. Avoid wrapping everything in cards. Embrace asymmetry.
→ See references/motion-design.md
Only animate transform and opacity. Use exponential easing (quart/quint/expo). 100-150ms for feedback, 200-300ms for state changes, 300-500ms for layout. Always support prefers-reduced-motion.
→ See references/interaction-design.md
Design all 8 states (default, hover, focus, active, disabled, loading, error, success). Use :focus-visible for keyboard-only focus rings. Prefer optimistic UI and undo over confirmation dialogs.
→ See references/responsive-design.md
Mobile-first with min-width queries. Use container queries for components. Detect input method ( pointer: fine/coarse), not just screen size. Handle safe areas.
→ See references/ux-writing.md
Specific verb + object for buttons. Every error message answers what/why/how-to-fix. Empty states are onboarding moments. Pick one term and stick with it.
If someone sees this interface and immediately thinks "AI made this" — that's the problem. Avoid: cyan-on-dark, purple gradients, glassmorphism everywhere, identical card grids, gradient text, dark mode with glowing accents. Make unexpected, intentional design choices.
Before doing design work, you MUST have confirmed design context:
.impeccable.md in project rootIssueSolution"Not authenticated"Set CLOUDFLARE_API_TOKEN env var or run wrangler loginNode version errorRequires Node.js v20+No config foundRun from project root with wrangler.toml or wrangler.jsoncConfig changes ignoredJSON takes precedence over TOML if both existBinding not foundCheck wrangler config bindings match code referencesCustom domain not workingDomain must be proxied (orange cloud) in CF DNSSSL pendingWait 1-5 min for automatic certificate provisioning
ScriptPurposescripts/create-project.shScaffold project from CF templatesscripts/deploy.shDeploy worker with pre-checksscripts/setup-domain.shConfigure custom domain via CF APIscripts/provision-d1.shCreate D1 database + binding snippetscripts/provision-kv.shCreate KV namespace + binding snippetscripts/provision-r2.shCreate R2 bucket + binding snippetscripts/provision-queue.shCreate queue + binding snippetscripts/manage-secrets.shAdd/list/delete/bulk secretsscripts/status.shDeployment status, resources, logsscripts/teardown.shDelete worker + resources
FileTopicreferences/cf-templates.mdAll 36+ CF quickstart templatesreferences/custom-domains.mdDomain setup, DNS, routes, SSLreferences/wrangler-config.mdFull wrangler.toml/jsonc referencereferences/typography.mdFont selection, scales, loadingreferences/color-and-contrast.mdOKLCH, palettes, dark modereferences/spatial-design.mdGrids, spacing, hierarchyreferences/motion-design.mdAnimation timing, easingreferences/interaction-design.mdStates, forms, focus, loadingreferences/responsive-design.mdMobile-first, fluid, container queriesreferences/ux-writing.mdLabels, errors, empty states