-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
50 lines (40 loc) · 1.28 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
const fs = require('fs');
const https = require('https');
const express = require('express');
const socketio = require('socket.io');
const config = require('./src/common/config');
const logger = require('./src/common/modules/logger');
const expressLoader = require('./src/common/modules/express');
const socketIoLoader = require('./src/handlers/socket.handler');
const { START_MESSAGE } = require('./src/common/constants/express');
const app = express();
const initLocalServer = async () => {
await expressLoader(app);
const key = fs.readFileSync('cert.key');
const cert = fs.readFileSync('cert.crt');
const server = https.createServer({ key, cert }, app);
const io = socketio.listen(server);
await socketIoLoader(io);
server.listen(config.port, () => {
logger.info(START_MESSAGE);
});
};
const initProdServer = async () => {
await expressLoader(app);
const server = app.listen(config.port, () => {
logger.info({ message: START_MESSAGE });
});
const io = socketio.listen(server, { path: '/signaling/' });
await socketIoLoader(io);
};
switch (config.envMode) {
case 'prod':
initProdServer();
break;
case 'dev':
initProdServer();
break;
default:
initLocalServer();
break;
}