Skip to content

Commit

Permalink
move edgeConfigClient outside of handler
Browse files Browse the repository at this point in the history
The edge config should be created outside of the handler. You might even want to move the whole SplitFactory client outside of the handler in case it makes sense to remove those across requests, or maybe just the PluggableStorage or the EdgeConfigWrapper.
  • Loading branch information
dferber90 authored Jul 12, 2023
1 parent c938d28 commit e7e211d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ The project overall architecture is ilustrated in the following diagram:
// Deploying as an Edge function here, but you can also use it on Edge middlewares and Serverless functions
export const config = { runtime: "edge" };

// Creates a client which knows how to read from Edge Config
// This client is defined outside of the handler so that it can be reused across requests
const edgeConfigClient = createClient(process.env.EDGE_CONFIG);

export default async function handler(req, event) {
// Extract user key. In this case from a request query param
const { searchParams } = new URL(req.url);
Expand All @@ -45,7 +49,7 @@ The project overall architecture is ilustrated in the following diagram:
edgeConfigItemKey: '<YOUR_EDGE_CONFIG_ITEM_KEY>',
// The Edge Config client. In this case, we are passing the default client
// that reads from the Edge Config stored in process.env.EDGE_CONFIG
edgeConfig: createClient(process.env.EDGE_CONFIG)
edgeConfig: edgeConfigClient,
})
}),
// Disable or keep only ERROR log level in production, to minimize performance impact
Expand Down

0 comments on commit e7e211d

Please sign in to comment.