-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (42 loc) · 1.25 KB
/
index.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
const CryptoJS = require('crypto-js');
const secret = "tombrady5rings";
const JsonFormatter = {
stringify: function(cipherParams) {
// We're not sringyfying here
},
parse: function(jsonStr) {
// parse json string
var jsonObj = JSON.parse(jsonStr);
var cipherParams = CryptoJS.lib.CipherParams.create({
ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct)
});
if (jsonObj.iv) {
cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv);
}
if (jsonObj.s) {
cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s);
}
return cipherParams;
}
};
const handler = async (event) => {
const url = 'https://web.pulsepoint.org/DB/giba.php?agency_id=65060';
return fetch(url, { cf: { cacheEverything: true } }).then(async function(response) {
if (response.ok) {
let json = await response.json();
var decrypted = CryptoJS.AES.decrypt(JSON.stringify(json), secret, {
format: JsonFormatter
}).toString(CryptoJS.enc.Utf8);
const body = JSON.parse(decrypted);
return {
'statusCode': 200,
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin' : '*',
},
'body': body,
}
}
});
};
exports.handler = handler;