Deploy
Ship a Flare app to Cloudflare Workers with cf, app.export(), and wrangler.
Deploy a Flare app to Workers by swapping the adapter, exporting the fetch handler, and setting nodejs_compat in Wrangler.
- Build the host with the
cfadapter from@flare-ts/core/cloudflare. - Export
app.export()as the module default. - Enable
nodejs_compatinwrangler.toml. Supply Flare config withbuildCf(flareJson)orbuildCf(flareJson, env), not[vars]. - Run
npx wrangler deploy.
import { FlareHost, FlareResponse } from "@flare-ts/core";import { cf } from "@flare-ts/core/cloudflare";
const host = new FlareHost(cf);host.http.get("/health", () => new FlareResponse(200, { ok: true }));
const app = host.build();export default app.export();name = "my-flare-app"main = "src/main.ts"compatibility_flags = ["nodejs_compat"]Wrangler [vars] land on the runtime Worker env and reach your code through Bindings; they are not read as Flare config. To set FLARE__* values, pass an env record as buildCf(flareJson, env).
app.export() returns a WorkerExportedHandle. That is the { fetch } shape Workers expects, so it goes straight to export default.
Use scoped services
Section titled “Use scoped services”Workers have no process-wide singletons:
class Clock extends FlareService { public static override deps = []; now() { return new Date().toISOString(); }}
const host = new FlareHost(cf);host.scoped(Clock);
host.http.get("/time", { inject: { clock: Clock } }, (_ctx, scope) => new FlareResponse(200, { time: scope.clock.now() }),);Bundle flare.json
Section titled “Bundle flare.json”Import config and pass it to buildCf when you do not want every value in [vars]:
import { buildCf } from "@flare-ts/core/cloudflare";import flareJson from "./flare.json" with { type: "json" };
const host = new FlareHost(buildCf(flareJson));Wrangler bundles the JSON at build time. Secrets still belong in wrangler secret put.
Durable Object bindings
Section titled “Durable Object bindings”When you register DOs, add the matching [[durable_objects.bindings]] entries and [[migrations]] in wrangler.toml. See Register and mount.
Related
Section titled “Related”- Cloudflare overview: constraints table
- Install: packages and
nodejs_compat - Log context: deferred work after the response