Overview
- 动态与公告
- 产品简介
- 购买指南
- 快速入门
- 域名服务
- 托管域名 DNS 解析
- 接入加速域名
- HTTPS 证书
- 别称域名
- 流量调度
- 站点加速
- 概述
- 访问控制
- 智能加速
- 缓存配置
- 文件优化
- 媒体处理
- 网络优化
- URL 重写
- 修改头部
- 自定义错误页面
- 请求与响应行为
- 源站配置
- 边缘函数
- 安全防护
- 规则引擎
- 四层代理
- 概述
- 新建四层代理实例
- 修改四层代理实例配置
- 停用/删除四层代理实例
- 批量配置转发规则
- 获取客户端真实IP
- 通过 TOA 获取 TCP 协议客户端真实 IP
- 通过 Proxy Protocol V1/V2 协议获取客户端真实 IP
- 数据分析与日志服务
- 工具指南
- 最佳实践
- API 文档
- History
- Introduction
- API Category
- Making API Requests
- Site APIs
- Acceleration Domain Management APIs
- Site Acceleration Configuration APIs
- Alias Domain APIs
- Security Configuration APIs
- Layer 4 Application Proxy APIs
- CreateL4Proxy
- ModifyL4Proxy
- ModifyL4ProxyStatus
- DescribeL4Proxy
- DeleteL4Proxy
- CreateL4ProxyRules
- ModifyL4ProxyRules
- ModifyL4ProxyRulesStatus
- DescribeL4ProxyRules
- DeleteL4ProxyRules
- CreateApplicationProxy
- ModifyApplicationProxy
- ModifyApplicationProxyStatus
- DescribeApplicationProxies
- DeleteApplicationProxy
- CreateApplicationProxyRule
- ModifyApplicationProxyRule
- ModifyApplicationProxyRuleStatus
- DeleteApplicationProxyRule
- Content Management APIs
- Data Analysis APIs
- Log Service APIs
- Billing APIs
- Certificate APIs
- Load Balancing APIs
- Diagnostic Tool APIs
- Version Management APIs
- Data Types
- Error Codes
- 常见问题
- 相关协议
- TEO 政策
- 联系我们
- 词汇表
Menu
addEventListener
注册事件监听器,是边缘函数的运行入口。
addEventListener
仅支持注册一个事件监听器。当前仅支持 fetch
请求事件,通过注册 fetch
事件监听器,生成 HTTP 请求事件 FetchEvent ,进而实现对 HTTP 请求的处理。描述
function addEventListener(type: string, listener: (event: FetchEvent) => void): void;
参数
参数名称 | 类型 | 必填 | 说明 |
type | string | 是 | 事件类型。 当前仅支持 fetch 请求事件。非 fetch 请求事件,边缘函数引擎会主动抛出 Error 类型的异常。 |
listener | 是 | 事件监听器。用于处理事件回调。 注册 fetch 请求事件生成 FetchEvent 类的事件监听器。 |
示例代码
// 注册 fetch 请求事件监听器addEventListener('fetch', (event) => {// 响应客户端event.respondWith(new Response('Hello World!'));});