-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.ts
64 lines (59 loc) · 1.94 KB
/
handler.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
import 'source-map-support/register';
const https = require('https');
const defaultOptions = {
hostname: 'sandbox-api.coinmarketcap.com',
headers: {
'X-CMC_PRO_API_KEY': 'PLACEHOLDER'
}
};
export const getListing = async (_event, _context) => {
const options = Object.assign(defaultOptions, {path: '/v1/cryptocurrency/listings/latest?start=1&limit=5000&convert=USD'});
return new Promise((resolve, reject) => {
https.get(options, function (res) {
console.log("Got response: " + res.statusCode);
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
resolve({
headers: {
'Cache-Control': 'max-age=600',
'Access-Control-Allow-Origin': '*' // this is needed. it seems claudia.js otherwise enables this automatically. needs verification.
},
statusCode: 200,
body: body
});
});
}).on('error', function (e) {
console.log("Got error: " + e.message);
reject(e);
});
});
}
export const getQuotes = async (_event, _context) => {
let symbol = _event.pathParameters.symbol;
const options = Object.assign(defaultOptions, {path: `/v1/cryptocurrency/quotes/latest?symbol=${symbol}&convert=USD`});
return new Promise((resolve, reject) => {
https.get(options, function (res) {
console.log("Got response: " + res.statusCode);
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
resolve({
headers: {
'Cache-Control': 'max-age=600',
'Access-Control-Allow-Origin': '*' // this is needed. it seems claudia.js otherwise enables this automatically. needs verification.
},
statusCode: 200,
body: body
});
});
}).on('error', function (e) {
console.log("Got error: " + e.message);
reject(e);
});
});
}