In this example, an edge function is used to generate a JSON object, and the JSON object is accessed and previewed from a browser.
Sample Code
const data = {
content: 'hello world',
};
async function handleRequest(request) {
const result = JSON.stringify(data, null, 2);
return new Response(result, {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
});
}
addEventListener('fetch', event => {
return event.respondWith(handleRequest(event.request));
});
Sample Preview
In the address bar of the browser, enter a URL that matches a trigger rule of the edge function to preview the effect of the sample code.
References
Was this page helpful?