forked from Sunbird-Obsrv/obsrv-web-console
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
39 lines (32 loc) · 1.18 KB
/
index.ts
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
// import * as dotenv from 'dotenv';
// dotenv.config();
import helmet from 'helmet';
import express from 'express';
import path from 'path';
import cors from 'cors';
import app from './app';
import config from './shared/resources/appConfig';
import constants from './shared/resources/constants';
import { logger } from './shared/utils/logger';
import { mountRoutes } from './main';
import sharedMiddlewares from './shared/middlewares';
const port = config.PORT;
const globalErrorHandler = sharedMiddlewares.get('globalErrorHandler');
const invalidRouteHandler = sharedMiddlewares.get('invalidRoute');
app.set('port', port);
app.set('logger', logger);
app.disable('x-powered-by');
// app.use(helmet());
app.use(cors());
app.use(express.static(path.join(__dirname, 'build')));
// mount routers
mountRoutes(app);
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
invalidRouteHandler && app.use('*', invalidRouteHandler?.handler({}));
// global error handler
globalErrorHandler && app.use(globalErrorHandler?.handler({}));
app.listen(port, () => {
logger.log({ level: 'info', message: constants.SERVER_INIT.replace('${PORT}', port.toString()) });
});