Cloudflare Deployment
This page explains why EdgeChat is well suited to Cloudflare and how the deployment architecture keeps operating costs low.
Cloudflare Resources
- D1: persistent application data
- KV: session storage
- R2: chat attachments and avatars
- Durable Objects: real-time WebSocket rooms
- Static Assets: frontend files
- Cron Triggers: scheduled cleanup of expired messages
Cost Optimizations
- Static files are hosted directly by Cloudflare instead of being proxied manually through the Worker.
run_worker_firstintercepts only/api/*and/files/*.- Message cleanup uses native Cron Triggers instead of scheduling extra work during requests.
- File endpoints return cache headers to reduce repeated reads.
- Home-page initialization and admin overview data use aggregate APIs.
Runtime Configuration
The key settings in the current wrangler.toml are:
toml
[assets]
directory = "./frontend/dist"
not_found_handling = "single-page-application"
run_worker_first = ["/api/*", "/files/*"]
[triggers]
crons = ["0 19 * * *"]Security Boundaries
- Most APIs require authentication.
/api/admin/*additionally requires administrator privileges./files/:keycurrently uses public access by default.
