Hi
I’m trying to run a fetch post and save to an R2 bucket AFTER returning a response…
// this saves to R2
await doThing()
return new Response()
// this fires the fetch but does not save to R2
event.waitUntil(doThing())
return new Response()
const doThing = () =>
new Promise((resolve) => {
fetch('https://example.com', {
method: 'POST',
body: JSON.stringify({
foo: bar
}),
})
.then((res) => res.json())
.then(async (data) => {
await R2_BUCKET.put('key', data)
resolve()
})
})
Any ideas on what I’m doing wrong here?