Very simple worker

Hi guys

Just would need a very easy worker in JS. The use case is to fecth the response from the origin or the response that the edge send to customer (maybe that one) with status code => 500 for origin not avail. I guess it is 503 and 504.

Just a worker that fetch that status code and then it send to another site or page, instaed of as it is now (always online) sending an offline page or using cache,

thanks for the help, i am new on thse very promising workers stuff.

Hi there!

I unfortunately do not have a ready-made script for you that would do exactly what you are needing – my sincerest apologies about that, but it sounds to me like you might be able to modify our Conditional Response Workers script example to achieve functionality you’re needing.

The thing about this script I should mention is, that all the examples in the code block look like they use the Request properties to determine the response action – so you want to make sure that you are conditionally serving content based on the Response Object – in your case, the status code.

From here, once you have the basic building blocks of your conditional script, there are a number of response possibilities that you could experiment with to see which suits you best – even for instance, serving cached files using the Caching API – but, admittedly, not the simplest of scripts to write.

Anyway, I really hope this helps!

Best,
Peter

Thanks for the help. I may think that it is not a request from browser, as this would be more like a request from the origin or the response from edge to user, right? the statuscode will come from those sources, instead from a “user” request?

what you think?

Yes, that’s absolutely right – that’s why that script I provided might require some re-tooling to fit the Response object as opposed to the Request properties.

If you are familiar with Javascript, you can attempt this yourself, or perhaps a helpful community member might have something cooked up already :slight_smile:

I hope this helps!

Best,
Peter