Menu

1 / 2

Geo-Redirect Users at the Edge with Vercel + ApogeoAPI in 10 Lines

DEV Community·ApogeoAPI·7 months ago
#hxIYPcTQ
#nextjs#vercel#edge#software#country
Reading 0:00
15s threshold

If you serve users in multiple regions, geo-routing is one of those features that sounds complicated but is actually trivial on Vercel. Vercel's Edge Network already knows which datacenter is closest to the visitor — what's missing is enriching that with country / city / currency data so you can do something useful with it.

This tutorial: 10 lines of middleware that intercept every request, look up the visitor's country, and rewrite the URL to a locale-specific path. No client-side flicker, no double network round-trip.

Why edge instead of client-side?

The naive approach is detecting country in the browser via fetch() to your geo API after the page loads. Two problems:

Layout shift. The page renders in English, then 200ms later swaps to Spanish. Users notice.

Wasted server work.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.