2021-08-17 19:25:27 +00:00
|
|
|
const Container = require('./src/container');
|
|
|
|
const winston = require('winston');
|
2021-08-17 17:35:40 +00:00
|
|
|
const express = require('express');
|
2021-08-17 19:25:27 +00:00
|
|
|
|
|
|
|
const AsyncFs = require('./src/asyncfs');
|
|
|
|
const DateTimeProvider = require('./src/datetimeprovider');
|
|
|
|
const ApiRoutes = require('./src/routes/api');
|
|
|
|
const NotificationRepository = require('./src/notification/repository');
|
|
|
|
const NotificationFacade = require('./src/notification/facade');
|
|
|
|
const TransportProvider = require('./src/transport/provider');
|
|
|
|
const SubjectParser = require('./src/subjectparser');
|
|
|
|
|
|
|
|
|
|
|
|
const logger = winston.createLogger({
|
|
|
|
level: 'verbose',
|
|
|
|
});
|
|
|
|
|
|
|
|
logger.add(new winston.transports.Console({
|
|
|
|
format: winston.format.simple()
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
const container = new Container();
|
2021-08-17 19:38:20 +00:00
|
|
|
container.registerInstance('Logger', logger);
|
|
|
|
container.registerType('AsyncFs', AsyncFs);
|
|
|
|
container.registerType('DateTimeProvider', DateTimeProvider);
|
|
|
|
container.registerType('ApiRoutes', ApiRoutes);
|
|
|
|
container.registerType('NotificationRepository', NotificationRepository);
|
|
|
|
container.registerType('NotificationFacade', NotificationFacade);
|
|
|
|
container.registerType('TransportProvider', TransportProvider);
|
|
|
|
container.registerType('SubjectParser', SubjectParser);
|
2021-08-17 17:35:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
async function asyncMain()
|
|
|
|
{
|
2021-08-17 19:25:27 +00:00
|
|
|
let config;
|
|
|
|
|
|
|
|
if (await container.AsyncFs.exists('config.js'))
|
|
|
|
{
|
|
|
|
logger.verbose('Using config.js');
|
|
|
|
config = require('./config.js');
|
|
|
|
}
|
2021-08-17 17:35:40 +00:00
|
|
|
else
|
2021-08-17 19:25:27 +00:00
|
|
|
{
|
|
|
|
logger.verbose('No config.js found, using config.default.js');
|
|
|
|
config = require('./config.default.js');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-17 19:38:20 +00:00
|
|
|
container.registerInstance('Config', config);
|
2021-08-17 17:35:40 +00:00
|
|
|
|
2021-08-17 19:25:27 +00:00
|
|
|
|
|
|
|
await container.NotificationRepository.init();
|
2021-08-17 17:35:40 +00:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
app.use(express.urlencoded({ extended: false }));
|
|
|
|
|
2021-08-17 19:38:20 +00:00
|
|
|
app.use('/api', container.ApiRoutes.createRouter(express));
|
2021-08-17 17:35:40 +00:00
|
|
|
app.use('/', express.static('frontend/dist'));
|
|
|
|
|
2021-08-17 19:25:27 +00:00
|
|
|
app.listen(config.port, () =>
|
2021-08-17 17:35:40 +00:00
|
|
|
{
|
2021-08-17 19:25:27 +00:00
|
|
|
logger.info(`NotificationLatch listening at http://localhost:${config.port}`);
|
2021-08-17 17:35:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-17 19:25:27 +00:00
|
|
|
|
|
|
|
asyncMain()
|
|
|
|
.catch(err =>
|
|
|
|
{
|
|
|
|
logger.error(`Unhandled exception: ${err}`);
|
|
|
|
logger.verbose(err.stack);
|
|
|
|
});
|