首页>文档>边缘计算>直接返回静态页面

直接返回静态页面

// 示例 HTML 页面
const someHTML = `<!DOCTYPE html>
  <!DOCTYPE html>
  <html>
  <body>
  <h1>Hello World</h1>
  <p>This is all generated using a DuEdge</p>
  <iframe
      width="100%"
      height="800"
      src="https://su.baidu.com"
      frameborder="0"
      allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
      allowfullscreen
  ></iframe>
  </body>
  </html>
`;
async function handleRequest(request) {
    const init = {
        headers: {
            'content-type': 'text/html;charset=UTF-8',
        },
    };
    // 直接返回 HTML 页面
    return new Response(someHTML, init);
}
addEventListener('fetch', event => {
    return event.respondWith(handleRequest(event.request));
});
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索