Overview
First-class Cloudflare Workers integration for Vela applications.
Vela provides first-class support for Cloudflare Workers through the @velajs/cloudflare package. The integration follows the same modular architecture you already know, adapted for the Workers runtime.
Creating a Cloudflare Application
Use CloudflareFactory.create() to bootstrap your application:
import { CloudflareFactory } from '@velajs/cloudflare';
import { AppModule } from './app.module';
const app = CloudflareFactory.create(AppModule);
export default app;CloudflareFactory.create() returns a CloudflareApplication instance that serves as the Workers entry point.
CloudflareApplication
The CloudflareApplication exposes the handlers Workers expects:
| Property / Method | Description |
|---|---|
.fetch | Handles incoming HTTP requests |
.scheduled(event, env, ctx) | Handles cron trigger events |
.queue(batch, env, ctx) | Handles queue message batches |
.close() | Gracefully shuts down the application |
Export the application as the default export so Workers can invoke it:
export default app;Binding References
Cloudflare bindings (KV, D1, R2, etc.) live on c.env and are only available at request time. Vela uses a BindingRef pattern to capture them lazily on the first request:
KVModule.forRoot({ binding: 'MY_KV' })The binding string tells Vela which key to read from c.env. The underlying service resolves the real binding when the first request arrives.
wrangler.toml
A minimal wrangler.toml for a Vela application:
name = "my-vela-app"
main = "src/index.ts"
compatibility_date = "2024-01-01"Add binding-specific sections as needed (covered in the individual binding pages).
Lifecycle Hooks
Hook into the application lifecycle for initialization and cleanup.
Environment
Access Cloudflare Worker environment bindings directly.
Last updated on