直接响应边缘函数代码中的HTML页面。
示例代码
const html = `
<!DOCTYPE html>
<body>
<h1>Hello World</h1>
<p>This example was generated by Chinatelecom Cloud AccessOne BosonFaaS.</p>
</body>
`;
async function handleRequest(request) {
return new Response(html, {
headers: {
'content-type': 'text/html; charset=UTF-8',
},
});
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
示例预览
在浏览器地址栏中输入匹配到HTTP路由的URL,即可预览示例效果。
相关参考
- 运行时API:addEventListener
- 运行时API:Response
- 运行时API:FetchEvent