Worker Path Matching for cdn-cgi/imagedelivery
Hi I am trying to use a worker for the paths where Cloudlfare Images is trying to be accessed. But looks like worker is not triggered in page rules for this path: cdn-cgi/imagedelivery/
13 Replies
Sorry for tagging but @kian Do you know anyone who can help, this is kind of an urgent issue
Pretty sure you can’t run workers in front of the cdn-cgi paths.
Hmm, we are trying to migrate from Cloudflare Images to Cloudflare R2, so we created a plan assuming we would be able to redirect or use a worker for backwards compatibility, and it would use our new image urls
Is there any alternative way we can do this ?
Hmm I looked at bit more, and looks like Cloudflare will not even trigger any of our configuration if path starts with cdn-cgi
I believe there must be a still way to achieve what I am looking
What if you went the opposite way? You could make your image urls all use some other path like /images/<imageoptions>, and have the Worker handle going to image delivery or R2
You can also use transform rules like that: https://developers.cloudflare.com/images/transform-images/serve-images-custom-paths/, but you could accomplish the same thing if you're using a Worker
The problem is we have already few different mobile applications running by using cdn-cgi/imagedelivery/ for accessing images, and as you know for mobile, we must have backward compatibility, and we cannot update our image urls all at once, that is why I am looking for a solution like this.
If we cannot really redirect or manipulate cdn-cgi path, then I believe we would have to keep uploading all images into both Cloudflare images and R2 always until full migration is completed for weeks. And this will probably result in more than 2x Cost for us
We really need help here otherwise we will be in a position where we are paying insane amount money (more than 2-3k) for cloudflare images product and we don't want to get vendor lock in.
I mean do the transform rules that Chaika linked not work?
No, that is my point. Our mobile apps are accessing images using this path cdn-cgi/imagedelivery, and old versions of mobile apps will be used for months.
So, we would always need to manipulate this path cdn-cgi/imagedelivery so it can use r2 in the background.
Ah I see. Wrong direction
Shall we tag someone from cloudflare dev experts, they might have some suggestions I hope ?
what are you looking for?
Workers won't run in front of it, cdn-cgi is all special. You already know that though
Redirect Rules looks like they do, but would depend on your mobile app following redirects
you don't really have that many options. cdn-cgi is very special. I would consider how difficult it may be to alter the mobile app path as well. IF you could change it to a different path you could have a Worker and then a ton of flexiblity
Thank you for the idea of redirect rule. Redirect rule is triggered on cdn-cgi paths
I am gonna now try to first add redirect rule, and that new url will use worker to get the image from r2
Yes, this is also something I need to test, app should be behaving correctly and displaying images with 301 redirects
@Chaika Good news! App is correctly displaying redirected images!
Thank you for your help, really appreciate it
I will go head and start implementing this.
One note is I think it would be great to see this information in Cloudflare Docs, I believe some other folks can benefit.
the thing is they're not made the same, different cdn-cgi pathes are built in different ways with different behaviors
For example, url redirects/nothing works with cdn-cgi/trace, nor can /rum, etc
I wouldn't be surprised if the imagedelivery path is just an internal worker, would make sense with the behavior
One of those things where it's all sort of undefined/unsupported behavior, not sure if it would make sense for them to document as they may change it in the future
Hm I see, that makes sense