This topic describes event handlers and fetch events of EdgeRoutine (ER).
Register an event
You must call addEventListener
in the code of ER to register an event handler. The event handler is called each
time a client initiates a request. ER allows multiple event handlers to be called
at the same time to process blocked client requests.
respondWith
function, the chain of event handlers ends. Event handlers registered after respondWith
is called will not be called.addEventListener('fetch', a);
addEventListener('fetch', b);
Fetch events
A fetch event occurs when you call the FetchEvent operation to block requests sent
to Alibaba Cloud Content Delivery Content (CDN). To listen for fetch events, you must
call event.respondWith
to register an asynchronous function that returns a Promise object. A Promise object
must be resolved into a Response object that is returned to the client request. Otherwise,
ER throws exceptions.
- waitUntil: ensures that asynchronous tasks are completed even after the Response object is returned.
- respondWith: responds to the FetchEvent operation.
- info: a non-standard parameter that represents a JavaScript object. The JavaScript object contains special information, such as the geographic location, client IP address, request scheme, and device information, about the request fetched from Alibaba Cloud CDN.