forked from adinhodovic/terraform-cloudflare-maintenance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintenance.js
135 lines (112 loc) · 3.24 KB
/
maintenance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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')
// Allow users from configured IPs into site
if (WHITELIST_IPS !== "null") {
if (WHITELIST_IPS.split(',').indexOf(request.headers.get("cf-connecting-ip")) > -1)
{
return fetch(request)
}
}
// Allow users to access paths that are whitelisted using regex expressions
if (WHITELIST_PATH !== "null") {
const { pathname } = new URL(request.url);
if (pathname.match(WHITELIST_PATH))
{
return fetch(request)
}
}
// Return modified response.
return new Response(maintenancePage, {
status: 503,
headers: modifiedHeaders
})
}
const maintenancePage = `
<!doctype html>
<head>
<title>Site Maintenance</title>
<link href="https://fonts.googleapis.com/css2?family=${google_font}&display=swap" rel="stylesheet"/>
<meta content="width=device-width, initial-scale=1" name="viewport" />
<link rel="icon" href="${favicon_url}"/>
<style>
body {
text-align: center;
font-family: "${font}", sans-serif;
color: #0C1231;
}
.logo {
margin-top: 3rem;
max-height: 35px;
width: auto;
}
.content {
margin: 0 auto;
max-width: 1000px;
width: 90%;
}
.info {
margin: 0 auto;
margin-top: 3rem;
max-width: 500px;
}
h1 {
font-weight: 600;
font-size: 1.8rem;
}
.image-main {
margin-top: 3rem;
max-width: 90%;
}
hr {
border: 1px solid rgba(0, 0, 0, 0.08);
margin: 0 auto;
margin-top: 2rem;
margin-bottom: 1rem;
max-width: 90%;
}
a {
text-decoration: none;
color: #535353
}
a:hover {
color: #0C1231;
}
@media (min-width: 968px) {
.logo {
max-height: 45px;
}
h1 {
font-size: 2.5rem;
}
.info {
margin-top: 6rem;
}
hr {
margin-top: 6rem;
margin-bottom: 3rem;
}
}
</style>
</head>
<body>
<div class="content">
<img class="logo" src="${logo_url}" alt="${company_name}">
<div class="info">
<h1>Il sito é correntemente in manutenzione per aggiornamenti</h1>
<p>Ci scusiamo per eventuali disservizi e torneremo online al piú presto</p>
%{ if statuspage_url != "null" }
<p>You can follow the updated information on our <a href="${statuspage_url}">status page</a>.</p>
%{ endif }
<p>— ${company_name}</p>
</div>
<img class="image-main" src="https://i.imgur.com/0uJkCM8.png" alt="Maintenance image">
<hr />
<a href="mailto:${email}?subject=Maintenance">Nel frattempo ci puoi contattare a: ${email}</a>
</div>
</body>
`;