-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
58 lines (44 loc) · 1.7 KB
/
app.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
import dotenv from 'dotenv';
import express from 'express';
import path from 'path';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import cors from 'cors';
import * as requestCorrelationMiddleware from './middlewares/requestCorrelationId.js';
import { camelCaseRequest as camelCaseReqMiddleware } from './middlewares/camelCaseRequest.js';
import * as errorHandleMiddleware from './middlewares/errorHandling.js';
import * as logger from './utils/logger.js';
import * as monerod from './routes/v1/monerod/info.js';
import * as charts from './routes/v1/monerod/charts.js';
import * as system from './routes/v1/monerod/system.js';
import * as ping from './routes/ping.js';
import { addAlias } from 'module-alias';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
addAlias('module-alias/register');
dotenv.config();
const environment = process.env.NODE_ENV;
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(requestCorrelationMiddleware.default);
app.use(camelCaseReqMiddleware);
if (environment === 'development') {
app.use(morgan('dev', logger.morganConfiguration));
} else {
app.use(morgan('combined', logger.morganConfiguration));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', express.static('./ui/dist'));
}
app.use('/v1/monerod/info', monerod.default);
app.use('/v1/monerod/info', charts.default);
app.use('/v1/monerod/system', system.default);
app.use('/ping', ping.default);
app.use(errorHandleMiddleware.default);
app.use((req, res) => {
res.status(404).json();
});
export default app;