tencent cloud

All product documents
Tencent Cloud EdgeOne
addEventListener
Last updated: 2023-03-08 11:26:27
addEventListener
Last updated: 2023-03-08 11:26:27
This API is used to register an event listener for a target. The event listener triggers an edge function when the specified type of event is delivered to the target. Only one event listener takes effect for the same type of event. Only fetch request events are supported currently. If a fetch event occurs after a fetch event listener is registered, the event listener generates a FetchEvent object to process the HTTP request.

Overview

function addEventListener(type: string, listener: (event: FetchEvent) => void): void;

Parameters

Parameter
Type
Required
Description
type
string
Yes
Event type.
Only fetch request events are supported.
If you specify a request event type other than fetch, the Edge Functions engine throws an Error exception.
listener
(event: FetchEvent) => void
Yes
Event listener that is used to process event callbacks.
You can register a fetch event listener to generate FetchEvent objects.

Sample Code

// Register a fetch event listener.
addEventListener('fetch', (event) => {
// Respond to the client.
event.respondWith(new Response('Hello World!'));
});

References

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon