I would like to setup an automation so that when my origin server is offline (restarting, upgrading, etc), the user’s browser will automatically show a maintenance page, like:
“Sorry about this, we are just doing some quick maintenance and we’ll be right back.
If you need assistance urgently, please email us at support@…”
It’s fairly easy, you just check the statuscode if it’s 200 or response.ok?
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const response = await fetch('https://example.com')
if (!response.ok)
return new Response('Sorry about this, we are just doing some quick maintenance and we’ll be right back.')
return response
}
You can basically copy and paste any HTML you want if you follow the sample code, I’d prefer full control any day of the week rather than be locked to a subscription.