Skip to content

Server provider

The FlagshipServerProvider implements the OpenFeature server provider interface. The provider works in Cloudflare Workers, Node.js, and any server-side JavaScript runtime that supports the Fetch API.

Inside a Cloudflare Worker, you can pass the Flagship binding directly to the provider. This avoids HTTP overhead and is the recommended approach. Outside of Workers, initialize the provider with an app ID and account ID — each evaluation call makes an HTTP request to the Flagship evaluation endpoint.

Setup

Pass the Flagship binding directly to the provider. This is the recommended approach inside a Worker.

JavaScript
import { OpenFeature } from "@openfeature/server-sdk";
import { FlagshipServerProvider } from "@cloudflare/flagship";
export default {
async fetch(request, env) {
await OpenFeature.setProviderAndWait(
new FlagshipServerProvider({ binding: env.FLAGS }),
);
const client = OpenFeature.getClient();
const showNewCheckout = await client.getBooleanValue(
"new-checkout",
false,
{ targetingKey: "user-42", plan: "enterprise" },
);
if (showNewCheckout) {
return new Response("New checkout enabled!");
}
return new Response("Standard checkout.");
},
};

Configuration options

OptionTypeRequiredDescription
bindingFlagshipNoThe Flagship binding from env.FLAGS. Use this inside a Worker for best performance. Authentication is handled automatically through the binding.
appIdstringNoThe Flagship app ID from the Cloudflare dashboard. Required when not using a binding.
accountIdstringNoYour Cloudflare account ID. Required when not using a binding.
authTokenstringNoA Cloudflare API token with Flagship read permissions. Required when not using a binding.

Provide either binding or appId, accountId, and authToken.

Evaluation context

OpenFeature uses an evaluation context to pass user attributes to the flag provider. The targetingKey field is the primary user identifier.

Pass additional attributes alongside targetingKey to match targeting rules. For example, you can include plan, country, or any custom attribute your rules reference.

JavaScript
const value = await client.getBooleanValue("new-checkout", false, {
targetingKey: "user-42",
plan: "enterprise",
country: "US",
});

Available hooks

The SDK ships with two hooks that you can attach to the OpenFeature client.

  • LoggingHook — Logs structured information for every evaluation.
  • TelemetryHook — Captures timing and event data for observability.
JavaScript
import { LoggingHook, TelemetryHook } from "@cloudflare/flagship";
OpenFeature.addHooks(new LoggingHook(), new TelemetryHook());

Migrate from another provider

If you use another OpenFeature-compatible provider (for example, LaunchDarkly or Flagsmith), switch to Flagship by replacing the provider initialization. No changes are needed at evaluation call sites.

JavaScript
// Before
await OpenFeature.setProviderAndWait(
new LaunchDarklyProvider({ sdkKey: "..." }),
);
// After
await OpenFeature.setProviderAndWait(
new FlagshipServerProvider({
appId: "<APP_ID>",
accountId: "<ACCOUNT_ID>",
authToken: "<API_TOKEN>",
}),
);