- Welcome to Azion Docs
- Edge Application
- Edge Functions
- Edge Functions - JavaScript Examples
- JavaScript Examples - Deny a request based on Geoip
Deny a request based on Geoip
Based on the country code, accessed through event.request.metadata["geoip_country_code"]
, the request is denied or not by event.deny()
.
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)));
Related documentation
Didn’t find what you were looking for? Open a support ticket.