Cloudflare CORS Configuration

Hello. I was recently creating an API endpoint.
But, I don’t see any CORS in the headers. I believe they should be there.

Sorry if I couldn’t explain much, not really advanced in this.

Are you adding CORS response headers on your Origin?

By default, Cloudflare includes the “Origin” request header in the cache key, so you can give different CORS responses to different Origin requests, and Cloudflare will cache them separately (rather than just issuing an Access-Control-Allow-Origin: * response to effectively turn off CORS)

Yes, so, I am looking to accept requests from everyone.

You need to add the CORS response headers on your Origin. You could do this in Cloudflare Workers, but much easier to just add them on your own servers.

How would I do that using Cloudflare Workers?

Plenty of examples on to get you started, including Modify Response and CORS Header Proxy.

But just adding this on your API origin server is going to be easier, faster and probably cheaper.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.