CORS policy issue with Page Rules

Hi, and merry Christmas! :slight_smile:

I’m trying to render an image using JavaScript, but I run into CORS issues. Here is the context:

  • I use Cloudflare Images with my custom domain (domain.com/cdn-cgi/imagedelivery/…). If I use that, it works fine, and I’m able to render/download the image client-side using JavaScript, since it use the same domain.
  • I wanted to have a URL looking nicer than that, so I made a page rule redirecting image.domain.com/… to domain.com/cdn-cgi/imagedelivery/
  • I added a DNS A record: Name: Image, Content: 8.8.8.8
  • The image is accessible properly, but when I try to download it using JS, I run into a CORS issue.

What could I do to fix that?

When you try to download what? The image.domain.com URL?

Yes :slight_smile:

But it works fine from the domain.com/cdn-cgi/ url

The image.domain.com URL doesn’t contain an image. It contains a redirect response to tell you where you need to go to get the image. I recommend that you modify your JavaScript to follow redirects. I don’t do much coding, so I’m not sure what that logic would look like.

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