最近更新时间:2023.12.20 19:13:37
首次发布时间:2023.02.15 19:04:51
以下示例展示了如何通过边缘函数回复一段静态或动态生成的http页面。
async function handleRequest(event) { // 获得用户的客户端ip const clientIp = event.info ? event.info.clientIp : "N/A"; const request = event.request; const html = `<!DOCTYPE html> <body> <h1>Hello World</h1> <p>Hello from Sparrow Runtime.</p> <p>The visitor's ip is ${clientIp}</p> </body>`; return new Response(html, { headers: { "content-type": "text/html;charset=UTF-8", }, }); } addEventListener("fetch", event => { return event.respondWith(handleRequest(event)); })