Beeps85
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
Or even just a generic page ... what I have now is pretty basic, so it doesn't really matter
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
Is it possible there was something in the original code I had that would display this page correctly?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
This doesn't return any errors now. However, if I preview the worker, the bare bones page doesn't appear(it says nothing is here yet)
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
and it's giving an error
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
I'm using this
export default {
fetch(req) {
const res = await fetch(req);
if (res.status >= 500) {
return new Response(maintenancePageHtml);
}
return res;
}
}
const maintenancePageHtml =
<!DOCTYPE html>
<html lang="en" style="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Under Maintenance</title>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="false">
<meta name="robots" content="nocache">
<meta name="robots" content="noindex,nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center">
<h1>Under Maintenance!
<p>Check back in an hour</h1></p>
</body>
</html>
;'''35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
What would this replace in the code I provided?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
It was a maintenance code page I found doing a search for this; I'm not exactly the world's greatest developer so this is a bit of an unknown for me. Is there a generic template to use in this instance?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
const AUTH_KEY = "4dfgdgdgfdfgdn"
const AUTH_VALUE = "234242DFSAASD5432234423t5th"
const VALID_AUTH = AUTH_KEY + "=" + AUTH_VALUE;
addEventListener("fetch", event => {
event.respondWith(handle(event.request))
})
async function handle(request) {
const cookies = request.headers.get("Cookie") "";
// Check for cookie or token in url
if (cookies.includes(VALID_AUTH) request.url.includes(VALID_AUTH)) {
// User has a valid token, so show the original page
const originalResponse = await fetch(request);
const response = new Response(originalResponse.body, originalResponse);
// Store token in cookie if not included already
if (!cookies.includes(VALID_AUTH)) {
const tokenCookie =
return new Response(maintenancePageHtml, { headers: modifiedHeaders, status: 503, statusText: "Service Unavailable" }); } } const maintenancePageHtml =
${VALID_AUTH}; Path=/;
;
response.headers.set('Set-Cookie', tokenCookie);
}
return response;
} else {
// User should see the maintenance site
const modifiedHeaders = new Headers();
modifiedHeaders.set('Content-Type', 'text/html');
modifiedHeaders.append('Pragma', 'no-cache');
return new Response(maintenancePageHtml, { headers: modifiedHeaders, status: 503, statusText: "Service Unavailable" }); } } const maintenancePageHtml =
<!DOCTYPE html>
<html lang="en" style="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Under Maintenance</title>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="false">
<meta name="robots" content="nocache">
<meta name="robots" content="noindex,nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center">
<h1>Under Maintenance!
<p>Check back in an hour</h1></p>
</body>
</html>
;35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
I'm going to remove it for now
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
I did this, and now the site goes the custom page, even though the site isn't down
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
My failure mode is Fail closed (block)
35 replies
CDCloudflare Developers
•Created by Beeps85 on 1/26/2025 in #workers-help
How to successfully deploy a worker so a custom maintenance page appears if the website goes down?
35 replies