2022-04-18 18:22:00 +04:00
|
|
|
import config from './config';
|
2022-04-27 02:52:23 +04:00
|
|
|
import * as express from 'express';
|
|
|
|
import * as http from 'http';
|
2022-04-18 18:22:00 +04:00
|
|
|
import logger from './logger';
|
|
|
|
import DB from './database';
|
2022-04-27 02:52:23 +04:00
|
|
|
import { Express, Request, Response, NextFunction } from 'express';
|
2022-04-24 01:33:38 +04:00
|
|
|
import databaseMigration from './database-migration';
|
|
|
|
import statsUpdater from './tasks/stats-updater.service';
|
|
|
|
import nodeSyncService from './tasks/node-sync.service';
|
2022-04-27 02:52:23 +04:00
|
|
|
import NodesRoutes from './api/nodes/nodes.routes';
|
2022-04-29 03:57:27 +04:00
|
|
|
import ChannelsRoutes from './api/nodes/channels.routes';
|
2022-04-18 18:22:00 +04:00
|
|
|
|
|
|
|
logger.notice(`Mempool Server is running on port ${config.MEMPOOL.HTTP_PORT}`);
|
|
|
|
|
|
|
|
class LightningServer {
|
2022-04-27 02:52:23 +04:00
|
|
|
private server: http.Server | undefined;
|
|
|
|
private app: Express = express();
|
|
|
|
|
2022-04-18 18:22:00 +04:00
|
|
|
constructor() {
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
await DB.checkDbConnection();
|
2022-04-24 01:33:38 +04:00
|
|
|
await databaseMigration.$initializeOrMigrateDatabase();
|
2022-04-18 18:22:00 +04:00
|
|
|
|
2022-04-19 17:37:06 +04:00
|
|
|
statsUpdater.startService();
|
2022-04-24 01:33:38 +04:00
|
|
|
nodeSyncService.startService();
|
2022-04-27 02:52:23 +04:00
|
|
|
|
|
|
|
this.startServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
startServer() {
|
|
|
|
this.app
|
|
|
|
.use((req: Request, res: Response, next: NextFunction) => {
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
|
|
next();
|
|
|
|
})
|
|
|
|
.use(express.urlencoded({ extended: true }))
|
|
|
|
.use(express.text())
|
|
|
|
;
|
|
|
|
|
|
|
|
this.server = http.createServer(this.app);
|
|
|
|
|
|
|
|
this.server.listen(config.MEMPOOL.HTTP_PORT, () => {
|
|
|
|
logger.notice(`Mempool Lightning is running on port ${config.MEMPOOL.HTTP_PORT}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
const nodeRoutes = new NodesRoutes(this.app);
|
2022-04-29 03:57:27 +04:00
|
|
|
const channelsRoutes = new ChannelsRoutes(this.app);
|
2022-04-18 18:22:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const lightningServer = new LightningServer();
|