-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (30 loc) · 865 Bytes
/
server.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
require('dotenv-flow').config();
const appconfig = require('configs/appconfig');
const logger = require("configs/loggerconfig")(module);
const fs = require('fs');
const https = require('https');
const http = require('http');
const socketio = require('socket.io');
logger.info('Configuring app');
Promise.resolve(appconfig(true))
.then(data => {
let server;
if (process.env.NODE_ENV === 'production') {
server = http.createServer(data.app);
}
else {
const certOptions = {
key: fs.readFileSync('certs/server.key'),
cert: fs.readFileSync('certs/server.crt')
}
server = https.createServer(certOptions, data.app)
}
const io = socketio(server);
data.app.set('io', io);
server.listen(process.env.app_http_port, () => {
logger.info('Listening on port:'+server.address().port);
})
})
.catch(error => {
logger.error(error);
});