JavaScript Examples - Deny a request based on Geoip
Learn how to manage geographic restrictions using JavaScript to access geoip country codes and control content accessibility through a dynamic firewall.
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.
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.