Skip to content

FlagshipFlag

Source: src/Cloudflare/Flagship/Flag.ts

A feature flag in a Cloudflare Flagship app.

A flag maps a key to a set of variations plus targeting rules. Workers evaluate flags through the Flagship binding (or the REST evaluate endpoint); changing variations, rules, enablement, or the default variation takes effect without redeploying code. Everything except the flag key and the parent app is mutable in place.

Boolean flag

const app = yield* Cloudflare.FlagshipApp("Flags", {});
const flag = yield* Cloudflare.FlagshipFlag("NewCheckout", {
appId: app.appId,
key: "new-checkout",
defaultVariation: "off",
variations: { off: false, on: true },
});

String flag with multiple variations

const flag = yield* Cloudflare.FlagshipFlag("CheckoutFlow", {
appId: app.appId,
key: "checkout-flow",
defaultVariation: "v1",
variations: { v1: "classic", v2: "express", v3: "one-click" },
});

Serve a variation to a specific country

const flag = yield* Cloudflare.FlagshipFlag("DarkMode", {
appId: app.appId,
key: "dark-mode",
defaultVariation: "off",
variations: { off: false, on: true },
rules: [
{
priority: 1,
conditions: [
{ attribute: "country", operator: "equals", value: "US" },
],
serveVariation: "on",
},
],
});

Percentage rollout

const flag = yield* Cloudflare.FlagshipFlag("NewSearch", {
appId: app.appId,
key: "new-search",
defaultVariation: "off",
variations: { off: false, on: true },
rules: [
{
priority: 1,
conditions: [],
serveVariation: "on",
rollout: { percentage: 25 },
},
],
});
const flag = yield* Cloudflare.FlagshipFlag("NewCheckout", {
appId: app.appId,
key: "new-checkout",
enabled: false,
defaultVariation: "off",
variations: { off: false, on: true },
});