Skip to content

Deploy

Ship a Flare app to Cloudflare Workers with cf, app.export(), and wrangler.

AI generated, pending review Updated 10 days ago · Flare 0.3

Deploy a Flare app to Workers by swapping the adapter, exporting the fetch handler, and setting nodejs_compat in Wrangler.

  1. Build the host with the cf adapter from @flare-ts/core/cloudflare.
  2. Export app.export() as the module default.
  3. Enable nodejs_compat in wrangler.toml. Supply Flare config with buildCf(flareJson) or buildCf(flareJson, env), not [vars].
  4. Run npx wrangler deploy.
src/main.ts
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();
wrangler.toml
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.

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() }),
);

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.

When you register DOs, add the matching [[durable_objects.bindings]] entries and [[migrations]] in wrangler.toml. See Register and mount.