Global Config
Set up feature flags backed by Vercel Global Config
This guide walks you through setting up feature flags that read their definitions from a Vercel Global Config item. You'll manage flags via the CLI and evaluate them in your Next.js app.
No targeting or A/B bucketing
Global Config flags select the default or currently active scheduled variant for every request. This adapter does not implement targeting, so it cannot support visitor targeting or identity-based A/B bucketing. Use an adapter such as Vercel Flags for those use cases.
Install dependencies
npm i @octopus-energy/flags flags @vercel/global-configSet environment variables
Set GLOBAL_CONFIG to your Global Config
connection string.
This is required for both reading flags at runtime and managing them via the
CLI. EDGE_CONFIG is also supported as a fallback for existing projects.
# .env.local
GLOBAL_CONFIG="https://global-config.vercel.com/ecfg_...?token=..."Create a flag
Use the CLI to create your first flag in Global Config:
npm exec oe.flags global-config create my-flag -- --kind boolean --default-variant off --variant on=true --variant off=falseYou can also add a description and labels:
npm exec oe.flags global-config create my-flag -- \
--kind boolean \
--default-variant off \
--variant "on:Enabled=true" --variant "off:Disabled=false" \
--description "Enables the new feature"See the Global Config CLI docs for all available commands.
Declare the flag in code
Create a flags.ts file and declare your flag using the Global Config
adapter:
// flags.ts
import { createGlobalConfigAdapter } from "@octopus-energy/flags/global-config";
import { flag } from "flags/next";
const adapter = createGlobalConfigAdapter({ key: "flags" });
export const myFlag = flag({
key: "my-flag",
adapter,
});The adapter reads the flag's defaultVariant, variants, and description
from Global Config at evaluation time. If an activation period is active, it
serves the scheduled variant instead of the default.
Generate typed declarations
Generate a TypeScript declaration file that augments flags/next with typed
overloads for your flags:
npm exec oe.flags generate -- --global-config flags --out generated/flags.d.tsThis gives you autocomplete and type checking for flag keys and values. Re-run the command whenever you add or change flags. See the generate docs for details.
Evaluate the flag
Call the flag function directly in a Server Component:
// app/page.tsx
import { myFlag } from "../flags";
export default async function Page() {
const enabled = await myFlag();
return <div>{enabled ? "Feature is on" : "Feature is off"}</div>;
}Next steps
- Vercel Flags: Use Vercel's provider for targeting and identity-based rollouts.
- Storyblok experiments: Run A/B experiments through Storyblok middleware.
- Flags Explorer: Set up the discovery endpoint so the Vercel Toolbar can find and override your flags.
- Precompute: Evaluate flags at build time for statically generated pages.