Development Experience
Local development uses two composable processes: bkper app dev for the worker runtime (Miniflare, file watching, tunnel) and vite dev for the client UI with HMR. The project template runs both concurrently via npm run dev.
Local development uses two composable processes — the worker runtime and the client dev server — that run concurrently.
What runs
npm run devThe project template runs both processes via concurrently:
vite dev— Client dev server with HMR. Changes to Lit components reflect instantly in the browser. Configured invite.config.ts.bkper app dev— The worker runtime:- Miniflare — Simulates the Cloudflare Workers runtime locally for the web server and events handler.
- Cloudflare tunnel — Exposes the events handler via a public URL so Bkper can route webhook events to your machine.
- File watching — Server and shared package changes trigger automatic rebuilds via esbuild.
You can also run them independently: npm run dev:client for just the UI, or npm run dev:server / npm run dev:events for specific workers.
URLs
| Handler | URL |
|---|---|
| Client (Vite dev server) | http://localhost:5173 |
| Web server (Miniflare) | http://localhost:8787 |
| Events (via tunnel) | https://<random>.trycloudflare.com/events |
The Vite dev server proxies /api requests to http://localhost:8787 (configured in vite.config.ts). The tunnel URL is automatically registered as the webhookUrlDev in Bkper, so events from books where you’re the developer are routed to your local machine.
Configuration flags
You can run specific handlers independently:
# Start only the web workerbkper app dev --web
# Start only the events workerbkper app dev --events
# Override default portsbkper app dev --sp 8787 --ep 8791Client configuration
The client dev server is configured in vite.config.ts at the project root. This is a standard Vite config — add plugins, adjust settings, or customize the dev server as needed.
The template includes a Bkper auth middleware plugin that handles OAuth token refresh during local development, and an /api proxy to the Miniflare worker.
Local secrets
Environment variables for local development live in a .dev.vars file at the project root:
# .dev.vars (gitignored)BKPER_API_KEY=your-api-key-hereCopy from the provided template:
cp .dev.vars.example .dev.varsThese variables are available as c.env.SECRET_NAME in your Hono handlers during development.
KV storage
KV data persists locally in the .mf/kv/ directory during development. This means your data survives restarts — useful for testing caching and state patterns.
// Readconst value = await c.env.KV.get('my-key');
// Write with TTLawait c.env.KV.put('my-key', 'value', { expirationTtl: 3600 });See the Cloudflare KV documentation for more usage patterns.
Type generation
The env.d.ts file provides TypeScript types for the Worker environment — KV bindings, secrets, and other platform services. It’s auto-generated based on your bkper.yaml configuration and checked into version control.
Rebuild it after changing services or secrets in bkper.yaml:
bkper app buildThe development loop
- Run
npm run dev - Edit client code — see changes instantly via Vite HMR
- Edit server code — auto-rebuilds and reloads via esbuild watch
- Trigger events in Bkper — your local handler receives them via the tunnel
- Check the activity stream in Bkper to see handler responses
- Iterate
Debugging
- Server errors — Check the terminal output from
bkper app dev. Worker runtime errors appear here. - Event handler errors — Check the Bkper activity stream. Click on an event handler response to see the result or error, and replay failed events.
- Client errors — Use browser DevTools. The Vite dev server provides source maps.