-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathserver.js
More file actions
64 lines (52 loc) · 1.79 KB
/
server.js
File metadata and controls
64 lines (52 loc) · 1.79 KB
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
//Install express server
const express = require('express');
const path = require('path');
const https = require('https');
const app = express();
const cors = require('cors');
cors({credentials: true, origin: true});
app.use(cors());
// Serve only the static files form the dist directory
app.use(express.static(__dirname + '/dist/farmdashboard-front'));
app.get('/harvestFinance/vaults', function(req, res) {
https.get('https://api-ui.harvest.finance/vaults?key=41e90ced-d559-4433-b390-af424fdc76d6', (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
console.log('data: ' + data);
try {
return res.send(JSON.parse(data));
} catch (e) {
console.log('Error: ' + e);
return res.send("{}");
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
});
app.get('/matic-info', function(req, res) {
https.get('https://api.coingecko.com/api/v3/simple/price?include_last_updated_at=true&ids=matic-network&vs_currencies=usd', (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
try {
return res.send(JSON.parse(data)["matic-network"]);
} catch (e) {
console.log('Error: ' + e);
return res.send("{}");
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
});
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/farmdashboard-front/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);