forked from rareweave/glome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (51 loc) · 1.64 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
const { StargateClient } = require("@cosmjs/stargate");
let lmdb = require("lmdb");
let JSON5 = require("json5");
let consola = require("consola");
let autoLoad = require("@fastify/autoload");
const app = require("fastify")({ logger: true });
let fs = require("fs");
(async () => {
global.config = JSON5.parse(fs.readFileSync("./config.json5", "utf8"));
global.stargateClient = await StargateClient.connect(
config.gateways.rpcConfig
);
global.databases = {
codes: lmdb.open("./db/codes"),
cursors: lmdb.open("./db/cursors"),
contracts: lmdb.open("./db/contracts"),
transactions: lmdb.open("./db/transactions"),
transactionsContents: lmdb.open("./db/transactionsContents"),
interactions: {},
contentTypes: lmdb.open("./db/contentTypes"),
evaluationResults: lmdb.open("./db/evaluationResults"),
isExecuted: lmdb.open("./db/isExecuted"),
indexes: lmdb.open("./db/indexes"),
};
global.servedContractsIds = new Set(config.allowed.contractIds);
global.networkInfo = {};
let startSyncLoop = require("./syncer.js");
startSyncLoop();
})();
const start = async () => {
app.addHook("preHandler", (req, res, done) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "*");
res.header("Access-Control-Allow-Headers", "*");
const isPreflight = /options/i.test(req.method);
if (isPreflight) {
return res.send();
}
done();
});
app.register(autoLoad, {
dir: require("path").join(__dirname, "routes"),
});
try {
await app.listen({ port: config.port });
} catch (err) {
app.log.error(err);
process.exit(1);
}
};
start();