-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.tftpl
36 lines (29 loc) · 929 Bytes
/
function.tftpl
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
function handler(event) {
const request = event.request
%{if redirectable_domains != null && length(redirectable_domains) > 0}
const redirectableDomains = [
%{for domain in redirectable_domains ~}
"${domain}",
%{endfor ~}
]
const hostIsRedirectable = redirectableDomains.some((domain) => request.headers.host.value === domain)
if (hostIsRedirectable) {
const url = `https://${domain_name}$${request.uri}`;
const response = {
statusCode: 302,
statusDescription: "Found",
headers: {
location: { value: url }
},
cookies: request.cookies
}
return response;
}
%{endif}
const oldUri = request.uri
const newUri = oldUri.replace(/\/$/, "/index.html")
console.log("Old URI: " + oldUri)
console.log("New URI: " + newUri)
request.uri = newUri
return request;
}