Node express js server on EC2 cors error when proxied with cloudfare

I have an express API in EC2 and have used Cloudflare with it. I got cors error so I changed from Cloudflare to route 53. Surprisingly no cors error when I send get or post request from my to my which is in EC2. While using Cloudflare if I change DNS settings to turn off proxy and just use DNS only then again no cors error.

I believe I am missing any crucial setup or config. And Cloudflare proxy pass is maybe not letting cors headers pass through. I also read several articles on this same topic and most of the conversations have ended midway or resolving on own. I have tried the rules for modify response header but didn’t work.
Is there any workaround this? Now I am sure it’s proxy enabled option of Cloudflare causing this.

CORS header also depends on the browser if they allows or not (default).
If you want to CF returns header like Access-Control-Allow-Methods, you can use Transform Rules.

You can also check out:

Cross-Origin Resource Sharing (CORS) · Cloudflare Cache (CDN) docs
CORS header proxy · Cloudflare Workers docs

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