James
01/02/2022, 5:00 PMWilliam | Chaos Management
01/02/2022, 5:04 PMsteranevdy
01/03/2022, 3:23 AMfetch
?Erwin
01/03/2022, 3:43 AMAbortController
now.. so https://developer.mozilla.org/en-US/docs/Web/API/AbortController should workHardAtWork
01/03/2022, 3:44 AMPromise.race()
, but that is much cleaner.Erwin
01/03/2022, 3:46 AMHardAtWork
01/03/2022, 4:00 AMjs
const betterFetch = async(e,t)=>{const r=new AbortController,o=r.signal,i=await Promise.race([new Promise(((e,t)=>setTimeout(e,s,"request timed out"))),fetch(e,{signal:o,...t})]);var s;if("request timed out"===i)throw r.abort(),i;return i};
Cloudflare Workers Bot
01/03/2022, 4:00 AMjavascript
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const sleep = delay => new Promise((resolve, reject) => setTimeout(resolve, delay, "request timed out"));
async function handleRequest(req) {
return betterFetch(req);
}
const betterFetch = async (o, t) => {
const abortController = new AbortController(),
signal = abortController.signal,
res = await Promise.race([sleep(2000), fetch(o, {signal, ...t})]);
if(res === "request timed out") {
abortController.abort();
throw res;
}
return res;
}
Erwin
01/03/2022, 4:10 AMHardAtWork
01/03/2022, 4:11 AMErwin
01/03/2022, 4:15 AMsteranevdy
01/03/2022, 5:49 AMHardAtWork
01/03/2022, 6:52 AMSirJosh
01/03/2022, 7:21 AMesbuild
is normally called to introduce some plugins for node compat (see attached patchfile). is there any way to modify the behavior of cloudflare pages when building functions?HardAtWork
01/03/2022, 7:33 AMSirJosh
01/03/2022, 7:34 AM_workers.JS
file is?SirJosh
01/03/2022, 9:18 AMSirJosh
01/03/2022, 9:18 AMSirJosh
01/03/2022, 9:20 AMSirJosh
01/03/2022, 10:11 AMsteranevdy
01/03/2022, 10:47 AMsteranevdy
01/03/2022, 10:51 AMsteranevdy
01/03/2022, 10:51 AMmaximillian
01/03/2022, 2:25 PM`The package "XXX" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.`
maximillian
01/03/2022, 2:28 PMmaximillian
01/03/2022, 2:57 PMmaximillian
01/03/2022, 2:59 PMfunctions
folder, but it doesn't have one...
https://github.com/cloudflare/stripe.pages.devmaximillian
01/03/2022, 2:59 PMfunctions
or not?Walshy | Pages
01/03/2022, 3:00 PM