-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
37 lines (33 loc) · 959 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
34
35
36
37
/* For env file function */
const dotenv = require('dotenv');
dotenv.config();
if (!process.env.PORT) {
console.log('Please configure env file.')
console.log('Copy .env.default to .env and configure the values.')
return
}
const fs = require('fs');
if(process.env.HTTPS=="true")
{
var http = require('https');
var options = {
key: fs.readFileSync(process.env.HTTPS_KEY),
cert: fs.readFileSync(process.env.HTTPS_CERT)
};
}
else
{
var http = require('http');
var options = {};
}
const app = require('./node/app');
const socketController = require('./node/controllers/socket_controller');
const httpPort = process.env.PORT || 8080;
const server = http.createServer(options,app);
const io = require('socket.io')(server);
global.io = io; //added
io.sockets.on('connection', socketController.respond );
const agenda = require('./node/agenda');
server.listen(httpPort);
agenda.start()
console.log('Server listening on ' + ':' + httpPort)