-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathredirecturl.js
More file actions
31 lines (28 loc) · 837 Bytes
/
Copy pathredirecturl.js
File metadata and controls
31 lines (28 loc) · 837 Bytes
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
'use strict';
exports.handler = (event, context, callback) => {
var raw_json=JSON.stringify(event);
var searchMask = '"host"';
var regEx = new RegExp(searchMask, "ig");
var replaceMask = '"Host"';
raw_json = raw_json.replace(regEx, replaceMask);
event=JSON.parse(raw_json);
const request = event.Records[0].cf.request;
var str=request.headers.Host[0].value;
var updated_host = request.headers.Host[0].value;
if (str.startsWith("www")){
updated_host = str.replace("www.","");
}
var location = "https://" + updated_host + request.uri;
const response = {
status: '302',
statusDescription: '302 Found',
headers: {
location: [{
key: 'Location',
value: location,
}],
}
};
console.log(response);
callback(null, response);
};