本文介绍返回1个JSON示例场景及结果。

代码

async function handler(event) {
  const data = {
    hello: "EdgeRoutine"
     }
  const json = JSON.stringify(data, null, 2)
  return new Response(json, {
      headers: {
        "content-type": "application/json;charset=UTF-8"
      }
    })
}

addEventListener('fetch', (event) => {
    event.respondWith(handler(event));
});

结果

返回JSON