Using Edge Config with Hypertune
This guide will help you get started with using Vercel's Hypertune integration with Edge Config. This integration allows you to use Edge Config as a configuration source for your Hypertune feature flags.
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
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); }
Now that you have set up the Hypertune Edge Config integration, you can explore the following topics to learn more:
Was this helpful?