Multi-Server origin - Purge problems

I am using workers in order to direct requests to my origin into 2 servers.
I direct to a first server, and if the file is not present I direct to another.

The problem is that file purge are now a problem with the API or UI.
what happens is that the request is being modified by the worker, in order to go to the first server, which has a different domain than my website.

And this is the url that is saved on Cloudflare edge server.

so when I try to purge the file, the url doesn’t match.
AND
I cannot use the real url to be purged because in the UI purge tool, you are only allowed to purge URL from within the domain name of your account.

I asked customer service to purge one for me and they comfirmed the problem
my only other solution is of course to purge all. which I have not tried but MAY work, but it is not really an option for my site as the traffic load generated by this command is very high.

I am using other CDNs, like fastly, and they handle this kind of multi-origin server seamlessly.

I hope the tech team can fix this.

PS: I cannot change the domain of my first server as it is google cloud servers url:
https://storage.googleapis.com/bucketname/

PS2: see below the code I am using for my worker
addEventListener(“fetch”, event => {
event.respondWith(fetchAndModify(event.request));
});

async function fetchAndModify(request) {
console.log(“got a request:”, request);
const gcs_request = “https://storage.googleapis.com/bucketname/”+request.url;
console.log("trying on gcs: "+gcs_request);
let response = await fetch(gcs_request);
console.log(response.headers);
return response;
}

I wanted to update our worker code to something more readable:

addEventListener("fetch", event => {
  event.respondWith(fetchAndModify(event.request));
});

async function fetchAndModify(request) {
  // first try on our bucket, after removing our domain
  const gcs_request = "https://storage.googleapis.com/mybucket/"+request.url.replace("https:/www.mywebsite.com/", "");
	console.log("trying on gcs: "+gcs_request);
	let response = await fetch(gcs_request);
	if(response.status != 200){
  	console.log("fallback on origin");
    response = await fetch(request);
	}
	return response;

}

Hi @daixtech,

Unfortunately, at present it is not possible to purge a single resource that came from a non-Cloudflare third party. You can do “purge everything” to purge all such resources, but you can’t selectively purge yet. We’re working on it!

3 Likes

+1 for that request: being able to address assets with a cache key that identifies their origin, and being able to purge them selectively using that key.

1 Like

Is there a way to purge files from third party domains yet? I’m also proxying some requests to GCS and want to be able to purge expired items via API.

So far clouflare has still not solved this problem

Sounds like we should be able clear the cache we own … but not yet …

I hope more people will request this feature as Cloudflare workers gets more fancy use

Update, this is now supported using the normal Cloudflare purge API. Just specify the full URL of the third-party resource you wish to purge!

2 Likes