Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/flagship/configuration.md
1# Flagship Configuration23## Wrangler Binding Setup45Add a Flagship binding to your Wrangler config to access flags via `env.FLAGS`.67### Single App89```jsonc10// wrangler.jsonc11{12"flagship": {13"binding": "FLAGS",14"app_id": "<APP_ID>"15}16}17```1819```toml20# wrangler.toml21[flagship]22binding = "FLAGS"23app_id = "<APP_ID>"24```2526### Multiple Apps2728```jsonc29// wrangler.jsonc30{31"flagship": [32{33"binding": "FLAGS",34"app_id": "<APP_ID_1>"35},36{37"binding": "EXPERIMENT_FLAGS",38"app_id": "<APP_ID_2>"39}40]41}42```4344```toml45# wrangler.toml46[[flagship]]47binding = "FLAGS"48app_id = "<APP_ID_1>"4950[[flagship]]51binding = "EXPERIMENT_FLAGS"52app_id = "<APP_ID_2>"53```5455### Generate Types5657After adding the binding, generate TypeScript types:5859```bash60npx wrangler types61```6263This creates the `Env` interface with each binding typed as `Flagship`:6465```typescript66interface Env {67FLAGS: Flagship;68EXPERIMENT_FLAGS: Flagship; // if multiple69}70```7172The `Flagship` type comes from `@cloudflare/workers-types`.7374---7576## OpenFeature SDK Installation7778### Server-Side (Workers, Node.js)7980```bash81npm i @cloudflare/flagship @openfeature/server-sdk82```8384### Browser8586```bash87npm i @cloudflare/flagship @openfeature/web-sdk88```8990---9192## SDK Provider Setup9394### Server Provider — With Binding (Workers)9596Recommended approach inside Workers. No HTTP overhead, auth handled automatically.9798```typescript99import { OpenFeature } from "@openfeature/server-sdk";100import { FlagshipServerProvider } from "@cloudflare/flagship";101102export default {103async fetch(request: Request, env: Env): Promise<Response> {104await OpenFeature.setProviderAndWait(105new FlagshipServerProvider({ binding: env.FLAGS }),106);107const client = OpenFeature.getClient();108// ... evaluate flags109},110};111```112113### Server Provider — With App ID (Node.js)114115For non-Worker runtimes. Requires an API token with Flagship read permissions.116117```typescript118import { OpenFeature } from "@openfeature/server-sdk";119import { FlagshipServerProvider } from "@cloudflare/flagship";120121await OpenFeature.setProviderAndWait(122new FlagshipServerProvider({123appId: "<APP_ID>",124accountId: "<ACCOUNT_ID>",125authToken: "<API_TOKEN>",126}),127);128const client = OpenFeature.getClient();129```130131### Client Provider (Browser)132133Pre-fetches flags on init, then evaluates synchronously. Only `prefetchFlags` are available.134135```typescript136import { OpenFeature } from "@openfeature/web-sdk";137import { FlagshipClientProvider } from "@cloudflare/flagship";138139await OpenFeature.setProviderAndWait(140new FlagshipClientProvider({141appId: "<APP_ID>",142accountId: "<ACCOUNT_ID>",143authToken: "<API_TOKEN>",144prefetchFlags: ["promo-banner", "dark-mode", "max-uploads"],145}),146);147await OpenFeature.setContext({ targetingKey: "user-42", plan: "enterprise" });148const client = OpenFeature.getClient();149```150151### Provider Options Reference152153**FlagshipServerProvider:**154155| Option | Type | Required | Description |156|--------|------|----------|-------------|157| `binding` | `Flagship` | No | Binding from `env.FLAGS`. Use inside Workers. |158| `appId` | string | No | App ID from dashboard. Required without binding. |159| `accountId` | string | No | Cloudflare account ID. Required without binding. |160| `authToken` | string | No | API token with Flagship read permissions. Required without binding. |161162Provide either `binding` or all three of `appId` + `accountId` + `authToken`.163164**FlagshipClientProvider:**165166| Option | Type | Required | Description |167|--------|------|----------|-------------|168| `appId` | string | Yes | App ID from dashboard |169| `accountId` | string | Yes | Cloudflare account ID |170| `authToken` | string | Yes | API token with Flagship read permissions |171| `prefetchFlags` | string[] | Yes | Flag keys to prefetch. Unlisted flags return `FLAG_NOT_FOUND`. |172173---174175## REST API Authentication176177For managing flags via the REST API (create, update, delete), set these environment variables:178179| Variable | Description |180|----------|-------------|181| `CLOUDFLARE_ACCOUNT_ID` | Your Cloudflare account ID |182| `CLOUDFLARE_API_TOKEN` | API token with Flagship permissions |183| `FLAGSHIP_APP_ID` | Target app UUID (from dashboard under **Compute > Flagship**, or `GET /apps`) |184185Base URL: `https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/flagship`186187```bash188curl -s -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \189"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/flagship/apps" | jq .190```191192App IDs are shown in the Cloudflare dashboard under **Compute > Flagship**.193194---195196## Local Development197198Flagship bindings work in local dev with `wrangler dev`. Flag evaluation uses the live Flagship configuration — there is no local flag store. Ensure the `app_id` in your Wrangler config points to a valid app.199200```bash201npx wrangler dev202```203