forked from getumbrel/umbrel-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (55 loc) · 2.35 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
59
60
61
62
63
64
65
66
require('module-alias/register');
require('module-alias').addPath('.');
require('dotenv').config();
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const passport = require('passport');
const cors = require('cors');
// Keep requestCorrelationId middleware as the first middleware. Otherwise we risk losing logs.
const requestCorrelationMiddleware = require('middlewares/requestCorrelationId.js'); // eslint-disable-line id-length
const camelCaseReqMiddleware = require('middlewares/camelCaseRequest.js').camelCaseRequest;
const onionOriginMiddleware = require('middlewares/onionOrigin.js');
const corsOptions = require('middlewares/cors.js').corsOptions;
const errorHandleMiddleware = require('middlewares/errorHandling.js');
require('middlewares/auth.js');
const logger = require('utils/logger.js');
const bitcoind = require('routes/v1/bitcoind/info.js');
const address = require('routes/v1/lnd/address.js');
const channel = require('routes/v1/lnd/channel.js');
const info = require('routes/v1/lnd/info.js');
const lightning = require('routes/v1/lnd/lightning.js');
const transaction = require('routes/v1/lnd/transaction.js');
const util = require('routes/v1/lnd/util.js');
const wallet = require('routes/v1/lnd/wallet.js');
const pages = require('routes/v1/pages.js');
const ping = require('routes/ping.js');
const app = express();
// Handle Cors for Tor Browser 9.0.0 bug and options requests
app.use(onionOriginMiddleware);
// Handles Cors for normal requests
app.use(cors(corsOptions));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(passport.initialize());
app.use(passport.session());
app.use(requestCorrelationMiddleware);
app.use(camelCaseReqMiddleware);
app.use(morgan(logger.morganConfiguration));
app.use('/v1/bitcoind/info', bitcoind);
app.use('/v1/lnd/address', address);
app.use('/v1/lnd/channel', channel);
app.use('/v1/lnd/info', info);
app.use('/v1/lnd/lightning', lightning);
app.use('/v1/lnd/transaction', transaction);
app.use('/v1/lnd/wallet', wallet);
app.use('/v1/lnd/util', util);
app.use('/v1/pages', pages);
app.use('/ping', ping);
app.use(errorHandleMiddleware);
app.use((req, res) => {
res.status(404).json(); // eslint-disable-line no-magic-numbers
});
module.exports = app;