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.
respondWithfunction, the chain of event handlers ends. Event handlers registered after respondWith is called will not be called.
addEventListener('fetch', a); addEventListener('fetch', b);
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
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.