JavaScript Examples - Functions on Firewall
Explore JavaScript-based Functions for robust firewall interactions, featuring event handling, HTTP header adjustments, and custom responses.
A general-purpose example for functions that run on the firewall, combining several request-handling actions in one handler. Use it as a starting point when you need to inspect incoming headers and metadata and then decide whether to block, drop, modify, or answer a request directly on Azion’s global network. The sample code exemplifies the following capabilities:
event.deny()event.drop()event.addRequestHeader()event.addResponseHeader()event.respondWith()event.continue()
How it works
The handler runs on the firewall event inside event.waitUntil() and reads several request headers with event.request.headers.get() to drive its decisions. Depending on which header is present, it can call event.deny() to return a 403, event.drop() to close the connection without a response, or event.addRequestHeader() and event.addResponseHeader() to inject custom headers. It can also short-circuit with event.respondWith(new Response(...)) to serve a custom JSON body, and it ends with event.continue() so that any request not already handled proceeds normally.