-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (31 loc) · 925 Bytes
/
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
const http = require('http');
exports.handler = function(event, context, callback) {
console.log("starting: " + new Date());
console.log("event: " + JSON.stringify(event));
console.log("context: " + JSON.stringify(context));
var request = http.get('http://time.jsontest.com', function(resp) {
var state = {
body: ''
};
resp.on('data', function(data) {
state.body += data;
});
resp.on('end', function() {
state.json = JSON.parse(state.body);
state.ending = (new Date());
console.log("result: " + JSON.stringify(state));
console.log("ending: " + state.ending);
callback(null, state.json);
});
});
request.on('error', function(e) {
console.log("error: " + new Date());
callback(e);
});
request.on('timeout', function(t) {
console.log("timeout: " + new Date());
request.abort();
callback(t);
});
request.end();
};