-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request
Description
It let's you respond rapidly, and then save data, which can be used to speed up subsequent requests.
https://developers.cloudflare.com/workers/about/tips/fetch-event-lifecycle/
let url = 'https://ca88e957.ngrok.io/log'
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
event.waitUntil(postLog(JSON.stringify({hello: 'hi'})))
})
function postLog(data) {
return fetch(url, {
method: 'POST',
body: data,
})
}
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(event) {
url = 'https://ca88e957.ngrok.io/magic'
return new Response('hello world', {status: 200})
}https://ca88e957.ngrok.io/magic is fetched after the repsonse is sent back.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request