Deny or allow a request based on the visitor’s country, resolved from GeoIP data on Azion’s global network. Use this pattern in a firewall function to enforce geographic restrictions, blocking traffic from specific regions before it ever reaches your application.

async function firewallHandler(event){
// Access the country code through geoip
let countryCode = event.request.metadata["geoip_country_code"]
// Do some logic here
// In this example, we are blocking access from Brazil
if (countryCode === "BR"){
event.deny();
}
// Then, if it comes from any other country,
// the processing continues
event.continue();
}
addEventListener("firewall", (event)=>event.waitUntil(firewallHandler(event)));

How it works

The function listens for the firewall event and runs its asynchronous handler inside event.waitUntil(). It reads the visitor’s country from event.request.metadata["geoip_country_code"], and when the request comes from Brazil it calls event.deny(), which returns a default 403 response and stops further processing. For requests from any other country, event.continue() allows the request to proceed normally to its destination.