tencent cloud

문서Tencent Cloud EdgeOne

addEventListener

Download
포커스 모드
폰트 크기
마지막 업데이트 시간: 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

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백