Deployment
The Maho Storefront deploys to Cloudflare Workers. A deployment updates the Worker code and static assets — catalog data is managed separately via sync.
Quick Deploy
# Build assets + deploy Worker
bun run build && bun run deployOr use the deploy script for demo environments:
./deploy.shDeployment Steps
1. Build Assets
bun run buildGenerates public/styles.css and public/controllers.js.txt. These are embedded in the Worker as text modules — no separate asset upload needed.
2. Deploy Worker
bun run deploy
# Runs: wrangler deployWrangler uploads the Worker with all bundled assets to Cloudflare. The deployment is instant and zero-downtime — the new Worker handles requests immediately.
3. Sync Data (if needed)
If the deployment includes changes to data handling, trigger a sync:
curl -X POST https://your-store.com/sync \
-H "Content-Type: application/json" \
-d '{"secret": "your-sync-secret"}'4. Purge Edge Cache (optional)
Normally unnecessary — the ASSET_HASH change automatically invalidates edge caches. For immediate propagation:
curl -X POST "https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/purge_cache" \
-H "Authorization: Bearer {API_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"purge_everything": true}'Environment Configuration
wrangler.toml
name = "maho-storefront"
main = "src/index.tsx"
compatibility_flags = ["nodejs_compat"]
[vars]
MAHO_API_URL = "https://your-maho-instance.com"
SYNC_SECRET = "your-secret"
[[kv_namespaces]]
binding = "CONTENT"
id = "your-kv-namespace-id"Multiple Environments
Use separate wrangler configs for staging vs. production:
# Production
wrangler deploy
# Staging
wrangler deploy --config wrangler.staging.toml
# Demo
wrangler deploy --config wrangler.demo-only.tomlZero-Downtime Deployments
Cloudflare Workers deployments are inherently zero-downtime:
- New Worker is uploaded and compiled
- Cloudflare atomically switches traffic to the new version
- In-flight requests on the old version complete normally
- Old cached pages continue serving until edge cache expires
The ASSET_HASH ensures old pages reference old asset URLs (still cached for 1 year), while new pages reference new URLs. No asset conflicts possible.
CI/CD Integration
Example GitHub Actions workflow:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: bun install
- run: bun run build
- run: bunx wrangler deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}Source: wrangler.toml, deploy.sh, package.json