This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
71 lines (50 loc) · 1.58 KB
/
main.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
67
68
69
70
71
const http = require('http');
const https = require('https');
const express = require('express');
const compression = require('compression');
const helmet = require('helmet');
const cors = require('cors');
const morgan = require('morgan');
const httpsLocal = require('https-local');
const { Logger } = require('euberlog');
const { SERVER: { PORT, PORT_HTTPS }, FRONTEND } = require('./utils/config');
const routes = require('./routes');
const app = express();
const logger = new Logger({ scope: 'MAIN' });
/* ADDING MIDDLEWARES */
logger.info('Adding middlewares...');
logger.debug('compression');
app.use(compression());
logger.debug('helmet');
app.use(helmet());
logger.debug('cors');
app.use(cors());
logger.debug('morgan');
app.use(morgan('dev'));
logger.debug('bodyParser');
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
logger.debug('express-static');
app.use(express.static(FRONTEND.PATH));
logger.success('Added middlewares!!!');
/* ADDING ROUTES */
logger.hr();
logger.info('Adding routes...');
app.use('/api', routes());
logger.success('Added routes!!!');
/* STARTING SERVER */
logger.hr();
logger.info('Starting https server...');
const httpsOptions = httpsLocal.options();
https.createServer(httpsOptions, app).listen(PORT_HTTPS);
logger.success('Server started!!!');
logger.debug(`Server listening on port ${PORT_HTTPS}`);
logger.hr();
logger.br();
logger.hr();
logger.info('Starting http server...');
http.createServer(app).listen(PORT);
logger.success('Server started!!!');
logger.debug(`Server listening on port ${PORT}`);
logger.hr();
logger.br();