A simple Cloudflare Workers setup using a pure code-only approach. This architecture provides:
- Code-First Configuration: All settings defined directly in TypeScript with full type safety
- Environment-Based Secrets: Sensitive values injected via environment variables
This setup runs in "code" mode only - all configuration is defined in your TypeScript files, with secrets provided through environment variables. No UI adjustments are possible, keeping the deployment simple and secure.
-
Split Configuration
bknd.config.ts- CLI configuration with platform proxy for Cloudflare resource accessconfig.ts- App configuration that prevents bundling CLI dependencies with your worker
-
Environment Integration
- Secrets and configuration values come from environment variables
- Type-safe access to environment variables through Wrangler types
- Static configuration with runtime environment injection
dev:cf- Cloudflare Workers development server with local environmentpredev- Generate TypeScript types before development
deploy- Deploy to Cloudflare Workers productionpreview- Test production mode locally with actual Cloudflare environment
bknd- Base CLI command with platform proxy and TypeScript support
typegen- Generate Wrangler types for environment variablespostinstall- Auto-setup: generate types and copy required assets
- Install:
npm install - Develop:
npm run dev:cf - Deploy:
npm run deploy
All application configuration is defined in config.ts. The example includes:
- Data Models: Entity definitions using bknd's schema builder
- Media Storage: S3-compatible storage configuration
- Mode: Always set to "code" for static configuration
Secrets and environment-specific values are injected via environment variables:
// Example from config.ts
media: {
adapter: {
type: "s3",
config: {
access_key: env.S3_ACCESS_KEY,
secret_access_key: env.S3_SECRET_ACCESS_KEY,
url: env.S3_URL,
},
},
},- Create required Cloudflare resources:
npx wrangler d1 create <database-name> - Update
wrangler.jsonwith your resource IDs
Set your environment variables using Wrangler CLI:
npx wrangler secret put S3_ACCESS_KEY
npx wrangler secret put S3_SECRET_ACCESS_KEY
npx wrangler secret put S3_URLOr use the Cloudflare Dashboard to set them via the web interface.