-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (38 loc) · 1.47 KB
/
index.js
File metadata and controls
55 lines (38 loc) · 1.47 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
import express from 'express';
import cors from 'cors';
import {dirname, join} from 'path';
import {fileURLToPath} from 'url';
import store from '../modules/store.js';
import {dbVoters, dbTrans} from '../helpers/DB.js';
import config from '../helpers/config/reader.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const publicDir = join(__dirname, '../../../web/dist/');
const app = express();
app.use(cors());
app.use('*.js', (req, res, next) => {
res.set('Content-Type', 'text/javascript');
next();
});
app.use('/', express.static(publicDir));
app.get('/', (req, res) => res.sendFile(join(publicDir, 'index.html')));
app.get('/api/get-transactions', async (req, res) => {
const transactions = await dbTrans.find({});
return res.send(transactions);
});
app.get('/api/get-voters', async (req, res) => {
const voters = await dbVoters.find({});
return res.send(voters);
});
app.get('/api/get-delegate', async (req, res) => res.send(store));
app.get('/api/get-config', async (req, res) => res.send({
version: config.version,
reward_percentage: config.reward_percentage,
donate_percentage: config.donate_percentage,
minpayout: config.minpayout,
payoutperiod: config.payoutperiod,
payoutperiodForged: store.periodInfo.totalForgedADM,
payoutperiodRewards: store.delegate.pendingRewardsADM,
payoutperiodPreviousRunTimestamp: store.periodInfo.previousRunTimestamp,
payoutperiodNextRunTimestamp: store.periodInfo.nextRunTimestamp,
}));
export default app;