-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (33 loc) · 1.12 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
const https = require("https");
exports.handler = async (event) => {
var result = '';
return new Promise((resolve, reject) => {
const options = {
host: 'api.nasa.gov',
path: '/planetary/earth/imagery/?lon=100.75&lat=1.5&date=2014-02-01&cloud_score=True&api_key=LrGt91Cceg0uBPp1ioaSbAbc4b8D08uPB81dQRfZ',
port: 443,
method: 'GET'
}
https.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
result += chunk;
});
res.on('end', () => {
console.log(result);
var data = JSON.parse(result)
resolve({
statusCode: 200,
body: JSON.stringify({earth_engine_url: data['url']}),
});
});
res.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
reject({
statusCode: 500,
body: JSON.stringify(e.message),
});
});
}).end();
});
}