Skip to content

Deployment Notes

BVE Gateway runs as a single Cloudflare Worker that serves both the API (api.bve.me) and the documentation site (docs.bve.me) via the Workers Assets binding.

  • Cloudflare account with Workers and D1 access
  • bun installed
  • wrangler (included as a dev dependency — use bunx wrangler)
Terminal window
# Create the D1 database
bunx wrangler d1 create bve_gateway
# Copy the returned database_id into wrangler.jsonc
# Create the event queue
bunx wrangler queues create bve-gateway-events

After creating the D1 database, update wrangler.jsonc with the returned database_id:

{
"d1_databases": [
{
"binding": "DB",
"database_name": "bve_gateway",
"database_id": "YOUR_DATABASE_ID_HERE"
}
]
}
Terminal window
bun run db:migrate:remote
Terminal window
bunx wrangler secret put FUELIX_API_KEY # Fuelix upstream API key
bunx wrangler secret put ADMIN_API_KEY # Admin key for /admin/* routes
bunx wrangler secret put API_KEY_PEPPER # Random 32+ char string for key hashing
Terminal window
bun run deploy

This command:

  1. Builds the Astro docs site (docs/dist/)
  2. Deploys the Worker with the built assets

The Worker is configured in wrangler.jsonc to respond on two custom domains:

{
"routes": [
{ "pattern": "api.bve.me", "custom_domain": true },
{ "pattern": "docs.bve.me", "custom_domain": true }
]
}

Add these domains in the Cloudflare dashboard under Workers & Pages > your Worker > Settings > Custom Domains, or they will be attached automatically on the next deploy if already configured as zones in your account.

The Worker routes based on hostname:

  • docs.bve.me → serves the Astro static site via the ASSETS binding
  • api.bve.me → runs the API gateway logic
Terminal window
# Copy example env file
cp .env.example .dev.vars
# Edit .dev.vars with real values (never commit this file)
# Apply migrations locally
bun run db:migrate:local
# Start local dev server
bun run dev

The local server runs at http://localhost:8787.

Configurable via wrangler.jsonc vars (non-secret):

VariableDefaultDescription
FUELIX_BASE_URLhttps://api.fuelix.ai/v1Fuelix upstream base URL
MONTHLY_WORKER_REQUEST_SOFT_CAP8500000Soft cap — returns 429
MONTHLY_WORKER_REQUEST_HARD_CAP9500000Hard cap — returns 503

Secrets (set via wrangler secret put):

SecretDescription
FUELIX_API_KEYFuelix upstream API key
ADMIN_API_KEYKey for /admin/* routes
API_KEY_PEPPERSHA-256 pepper for client key hashing
Terminal window
# Pull latest code
git pull
# Run migrations if schema changed
bun run db:generate
bun run db:migrate:remote
# Deploy
bun run deploy
Terminal window
bunx wrangler tail
CommandDescription
bun run devLocal development server
bun run deployBuild docs + deploy Worker
bun run tailStream live Worker logs
bun run typecheckTypeScript type check
bun test — ❌Use bun run test instead (Cloudflare pool)
bun run testRun test suite
bun run db:generateGenerate Drizzle migrations
bun run db:migrate:localApply migrations locally
bun run db:migrate:remoteApply migrations to production D1