-
-
Save clarkritchie/31aa63566ac388332cb2a6275a40396d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener("fetch", event => { | |
event.respondWith(fetchAndReplace(event.request)) | |
}) | |
async function fetchAndReplace(request) { | |
let modifiedHeaders = new Headers() | |
modifiedHeaders.set('Content-Type', 'text/html') | |
modifiedHeaders.append('Pragma', 'no-cache') | |
//Return maint page if you're not calling from a trusted IP | |
if (request.headers.get("cf-connecting-ip") !== "123.123.123.123") | |
{ | |
// Return modified response. | |
return new Response(maintPage, { | |
headers: modifiedHeaders | |
}) | |
} | |
else //Allow users from trusted into site | |
{ | |
//Fire all other requests directly to our WebServers | |
return fetch(request) | |
} | |
} | |
let maintPage = ` | |
<!doctype html> | |
<title>Site Maintenance</title> | |
<!-- | |
__________________ | |
\ \ | |
\ \ | |
\ \ | |
\ \ | |
/------------------------------------- | |
//---------------// / | | |
// // / __| | |
// // / / || | |
// // / / || | |
//_______________// o o / / || ___/-\___ | |
------------------------------------/ ------- | |---------| | |
| | | | | | | | | |
| BLUEBOARD, INC | | | | | | | | |
| | | | | | | | | |
|-----------------------------------| | | | | | | | |
| | | | | | | | | |
------------------------------------------------- |_______| | |
--> | |
<style> | |
body { | |
text-align: center; | |
padding: 150px; | |
background: url('data:image/jpeg;base64,<base64EncodedImage>'); | |
background-size: cover; | |
-webkit-background-size: cover; | |
-moz-background-size: cover; | |
-o-background-size: cover; | |
} | |
.content { | |
background-color: rgba(255, 255, 255, 0.75); | |
background-size: 100%; | |
color: inherit; | |
padding-top: 1px; | |
padding-bottom: 10px; | |
padding-left: 100px; | |
padding-right: 100px; | |
border-radius: 15px; | |
} | |
h1 { font-size: 40pt;} | |
body { font: 20px Helvetica, sans-serif; color: #333; } | |
article { display: block; text-align: left; width: 75%; margin: 0 auto; } | |
a:hover { color: #333; text-decoration: none; } | |
</style> | |
<article> | |
<div class="background"> | |
<div class="content"> | |
<h1></h1> | |
<p>This site is under maintenance</p> | |
<p>— <B>Blueboard Team</B></p> | |
</div> | |
</div> | |
</article> | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment