Using Edge Config with Hypertune
Learn how to use Edge Config with Vercel's Hypertune integration.Hypertune is a feature flag, A/B testing and app configuration platform with full type-safety and Git version control.
The Hypertune Edge Config integration enables you to access your feature flags and run A/B tests at ultra low latency at the edge.
Before using this integration, you should have:
-
A Hypertune project. If you don't have one, follow the Hypertune getting started guide
-
The latest version of Vercel CLI. To check your version, use
vercel --version
. To install or update Vercel CLI, use:pnpm i -g vercel@latest
-
A project. If you don't have one, you can run the following terminal commands to create a Next project:
pnpm i next
terminalnpx create-next-app@latest
-
A Vercel project. If you don't have one, see Creating a Project
-
An Edge Config. If you don't have one, follow the Edge Config quickstart
-
The Edge Config SDK:
pnpm i @vercel/edge-config
The following steps will walk you through:
- Configuring Vercel's Hypertune Edge Config integration
- Using it to check your feature flags from your frontend code
Visit the Hypertune page in the Integration Marketplace and select the Add Integration button. Then:
- Select a Vercel team and project
- Continue and log into Hypertune
- Connect your Hypertune project to an existing or new Edge Config store. Save the Hypertune Token, Connection String and Item Key for later
- Go to your Vercel dashboard and select the project you want to use the Hypertune integration with. Go to Settings > Environment Variables and add the following:
NEXT_PUBLIC_HYPERTUNE_TOKEN
, set to the Hypertune TokenEDGE_CONFIG
, set to the Connection StringEDGE_CONFIG_HYPERTUNE_ITEM_KEY
, set to the Item Key
First, install the Edge Config package:
pnpm i @vercel/edge-config
Then, pull your environment variables:
vercel env pull
Now, create a
hypertune.ts
file that initializes the Hypertune SDK.The following example passes an Edge Config client, your Hypertune Token, and your Edge Config Item Key to the Hypertune SDK:
lib/hypertune.tsimport { initializeHypertune } from '../generated/generated'; import { createClient } from '@vercel/edge-config'; const edgeConfigClient = createClient(process.env.EDGE_CONFIG!); const hypertune = initializeHypertune( {}, { token: process.env.NEXT_PUBLIC_HYPERTUNE_TOKEN, vercelEdgeConfigClient: edgeConfigClient, vercelEdgeConfigItemKey: process.env.EDGE_CONFIG_HYPERTUNE_ITEM_KEY, }, ); export default hypertune;
Finally, you can use the
hypertune
object you exported in the file above to check for feature flags in your Edge Middleware:middlware.tsimport { NextFetchEvent, NextRequest } from 'next/server'; import hypertune from './lib/hypertune'; export const config = { matcher: '/', }; export async function middleware( request: NextRequest, context: NextFetchEvent, ) { await hypertune.initFromServerIfNeeded(); const rootNode = hypertune.root({ context: { user: { id: 'test', name: 'Test', email: 'test@test.com' }, }, }); const exampleFlag = rootNode.exampleFlag().get(/* fallback */ false); console.log('Middleware feature flag: ', exampleFlag); }
Quickstart
Create and read from your Edge Config in minutes.
Read with the SDK
Read from your Edge Config at the fastest speeds.
Use the Dashboard
Manage your Edge Configs in the Vercel dashboard.
Manage with the API
Manage your Edge Configs with the Vercel API.
Edge Config Limits
Learn about the limits of Edge Configs.
Was this helpful?