Automatically route users to the closest or most appropriate content origin based on their geographic location using FastEdge's built-in GeoIP headers.
Features
- Country-level detection via
x-real-ipandgeoip-country-codeheaders - Continent-level fallback
- Custom redirect rules via config
- Zero-latency lookups — GeoIP data is resolved at the edge
Code
let country = req.headers()
.get("geoip-country-code")
.and_then(|v| v.to_str().ok())
.unwrap_or("unknown");
match country {
"DE" | "FR" | "NL" => redirect_to("https://eu.example.com"),
"US" | "CA" => redirect_to("https://na.example.com"),
_ => redirect_to("https://global.example.com"),
}