Any way to set global headers on Response?

I need to do this on every response for CORS…

response.headers.set('Access-Control-Allow-Origin', '*');

Would be awesome to be able to set a global config. Not only for CORS, also content type or auth headers.

Best solution that comes to mind would be Workers (or maybe there is an App between the various Cloudflare Apps, but not sure here).

hmmm yes, I’m referring to the Response object used in workers.

Then I don’t get the question… simply add the header using workers? :thinking:

The problem is that I’m generating many responses across my files in the same worker.

It’s an API not a single function responding to a single route.

Oh, gotcha!

There are no global settings, but you could modify the code such that you have some hooks pre-API and post-API, so that, for example, after the API is done and has prepared a reply it calls a specific function to generate the response that adds the common headers. This is the best way to do so, being JS in the end.

Yes, I’m doing something similar, but it would be great if there was a way to set up global headers like axios does for example.