Multi-Server origin - Purge problems


#1

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;
}


#2

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;

}


#3

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!


#4

+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.