Ok this is weird. I got it solved with a strange solution.
I toggled the development mode in cloudflare dashboard, which is “Temporarily bypass our cache. See changes to your origin server in realtime.”
Then it worked…! I turned off the dev mode and it still works. So apparently it was some cache issue. But the funny thing is, I have purged all cache in cloudflare multiple times. hmm maybe its a different set of cache