Honumael (MasterQuestMaster)
CDCloudflare Developers
•Created by Honumael (MasterQuestMaster) on 8/18/2024 in #workers-help
Worker is executed twice for each browser reload
Hello!
I'm trying to make a Cloudflare worker in VS Code, but I'm running into a weird behavior with it.
My worker has a "fetch" function in "index.ts" which I understand is the entry point for when the worker is called.
Inside of that function, I'm calling some functions that fetch more resources and then call an API with a POST request (also with fetch) to process that data.
I noticed during my debugging in VS Code (with an attached debugger on the dev server) that my worker is actually being called twice per reload after I reload it in the browser. When debugging, after the first request is completed, the cursor jumps back to my breakpoint in index.ts and executes the entire code again. After that is done, it doesn't happen again until I reload my browser to try again.
The worker being executed twice is a problem for me because it results in unnecessary API calls and traffic.
Has anyone experienced something like this before and can tell me why this happens and how to fix it?
5 replies
CDCloudflare Developers
•Created by Honumael (MasterQuestMaster) on 8/17/2024 in #workers-help
TypeScript error with global Response object
Hello!
So I'm trying to build a Worker with TypeScript. I'm using the regular node-internal "fetch" which seems to return a "global.Response". When I try to make a function that takes that Response as parameter of type "Response", TS complains that
Argument of type 'global.Response' is not assignable to parameter of type 'Response'.
Type 'Response' is missing the following properties from type 'Response': webSocket, cf, bytes
It seems there's a conflict between the Workers "Response" (https://developers.cloudflare.com/workers/runtime-apis/response/) and the integrated Response type. I cannot seem to use "global.Response" as an argument type, so does anyone know how to handle this conflict?8 replies