-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (55 loc) · 1.75 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const restify = require("restify");
const fs = require("node:fs");
const path = require("node:path");
const os = require("node:os");
const corsMiddleware = require("cors");
const { gravedigger } = require("./strategies/bluna");
const helpers = require(path.join(__dirname, 'helpers.js'));
const server = restify.createServer();
const cors = corsMiddleware({
credentials: true,
preflightMaxAge: 5,
origin: function (origin, callback) {
callback(null, origin);
},
});
server.pre(cors);
server.use(
restify.plugins.bodyParser({
maxBodySize: 0,
mapParams: true,
mapFiles: false,
overrideParams: false,
hash: "sha1",
rejectUnknown: true,
requestBodyOnGet: false,
reviver: undefined,
maxFieldsSize: 1024 * 1024,
})
);
fs.readdir("./strategies", (err, files) => {
if (err) {
throw err;
}
files.forEach(file => {
const endpoint = require(path.join(__dirname, "strategies", file));
server.get(`${endpoint.path}`, async (req, res) => {
const out = {
bondedAssetPrice: 0,
gravedigger: [],
token: {}
}
out.bondedAssetPrice = await helpers.getBondedAssetData(endpoint);
out.gravedigger = await helpers.getGravediggerData(endpoint);
// if (endpoint.token.contract.indexOf("factory") === -1) {
// out.token = await getTokenData(endpoint);
// } else {
// out.token = out.gravedigger;
// }
res.json(helpers.processData(out, endpoint.token))
})
});
server.listen(process.env.PORT, () => {
console.log("%s listening at %s", server.name, server.url);
});
})