-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedirection-307-v2.js
More file actions
34 lines (33 loc) · 1.08 KB
/
Copy pathRedirection-307-v2.js
File metadata and controls
34 lines (33 loc) · 1.08 KB
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
function handler(event) {
var redirects = {
'TW': '/legacy-files/',
'US': '/legacy-files/legacy/'
};
var headers = event.request.headers;
var originalPath = event.request.uri;
if (originalPath === '/legacy-files/legacy/') {
setTimeout(function() {
var country = headers['cloudfront-viewer-country'].value;
var newPath = originalPath;
if (country in redirects) {
newPath = redirects[country];
}
return {
statusCode: 307,
statusDescription: 'Temporary Redirect',
headers: { "location": { "value": newPath } }
};
}, 3000); // 3000毫秒 = 3秒
} else {
var newPath = originalPath;
var country = headers['cloudfront-viewer-country'].value;
if (country in redirects) {
newPath = redirects[country];
}
return {
statusCode: 307,
statusDescription: 'Temporary Redirect',
headers: { "location": { "value": newPath } }
};
}
}