Goal
I’d like to have all of our edge functions run only from EU edge nodes in order for our application to comply with GDPR privacy requirements.
Relevant Documentation
Configuring Regions for Vercel Functions says
You can set one or more preferred regions using the route segment config
preferredRegion
or specify aregions
key within a config object to set one or more regions for you functions to execute in
What I Tried
// lib/constants.js
export const PREFERRED_VERCEL_REGIONS = ['fra1', 'arn1', 'dub1'];
// app/api/edge-handler-one/route.js
import { PREFERRED_VERCEL_REGIONS } from '@/lib/constants';
export const preferredRegion = PREFERRED_VERCEL_REGIONS;
// app/api/edge-handler-two/route.js
import { PREFERRED_VERCEL_REGIONS } from '@/lib/constants';
export const preferredRegion = PREFERRED_VERCEL_REGIONS;
// app/api/edge-handler-three/route.js
import { PREFERRED_VERCEL_REGIONS } from '@/lib/constants';
export const preferredRegion = PREFERRED_VERCEL_REGIONS;
This results in the following error during build:
Error: Invalid request:
regions[0]
should be equal to one of the allowed values “cdg1, arn1, dub1, lhr1, iad1, sfo1, pdx1, cle1, gru1, hkg1, hnd1, icn1, kix1, sin1, bom1, syd1, fra1, cpt1”.
What Works
// app/api/edge-handler-one/route.js
export const preferredRegion = ['fra1', 'arn1', 'dub1'];
// app/api/edge-handler-two/route.js
export const preferredRegion = ['fra1', 'arn1', 'dub1'];
// app/api/edge-handler-three/route.js
export const preferredRegion = ['fra1', 'arn1', 'dub1'];
What I Would Like
Having to repeat the same literal in every edge file makes it harder to manage this list. Imagine this very likely scenario:
- Engineer A opens a pull request to modify the list of regions
- Engineer B opens a pull request that adds a new edge handler, copying the list of regions from an existing handler
Those pull requests don’t have any merge conflicts, so nothing stops the team from merging both, leaving the app in an inconsistent state.
But even centralizing the configuration in a constant wouldn’t solve the problem where an engineer adds a new handler and omits the preferredRegion
altogether.
Ideally, I’d be able to configure this list centrally and have it apply to all edge execution, both middleware and route handlers. Perhaps something like
// vercel.json
{
"edgeRegions" ['fra1', 'arn1', 'dub1']
}