I’m very new to Cloudflare, just created my first account.
I’m using workers to call a 3rd party API. The worker is hosted here: https://worker1.fp1.workers.dev/
Here is the worker code:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
let d1 = Date.now();
let apiResponse = await fetch("https://api.fpjs.io");
let diff = Date.now() - d1;
return new Response(`took ${diff} ms to call the API`, {
headers: { 'content-type': 'text/plain' },
})
}
When I’m testing the worker in the built-in editor, the API call takes 31-33ms consistently (after first start).
However when I’m testing it in actual browser, the API call takes ~600ms consistently.
This time difference is unfortunately a deal breaker for me, 31-33ms is perfect, while 600ms is not acceptable.
Why is this happening? Can I make it call the API in 33ms like it’s doing in the editor? Is there a way to seed it up?
I’m testing from Chicago, the API is hosted on AWS (N. Virginia).