首页>文档>边缘计算>直接返回JSON

直接返回JSON

// JSON 内容
const someJSON = {
    result: ['some', 'results'],
    errors: null,
    msg: 'this is a DuEdge generated json',
};
async function handleRequest(request) {
    const init = {
        headers: {
            'content-type': 'application/json;charset=UTF-8',
        },
    };
    // 直接返回 JSON
    return new Response(JSON.stringify(someJSON), init);
}
addEventListener('fetch', event => {
    return event.respondWith(handleRequest(event.request));
});
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索