forked from colloqi/pisignage-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
99 lines (78 loc) · 3.15 KB
/
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
// Default node environment to development
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var express = require('express'),
oldSocketio = require('919.socket.io'),
socketio = require('socket.io'),
mongoose= require('mongoose');
var path = require('path'),
fs = require('fs');
// Application Config
var config = require(path.join(__dirname,'/config/config'));
// Connect to database
mongoose.Promise = global.Promise;
mongoose.connect(config.mongo.uri, config.mongo.options,function(error){
if (error) {
console.log('********************************************');
console.log('* MongoDB Process not running *');
console.log('********************************************\n');
process.exit(1);
}
});
// check system
require('./app/others/system-check')();
// Bootstrap models
var modelsPath = path.join(__dirname, 'app/models');
fs.readdirSync(modelsPath).forEach(function (file) {
require(modelsPath + '/' + file);
});
console.log('********************************************************************');
console.log('* After update if you do not see your groups, please change *');
console.log('* change the uri variable to "mongodb://localhost/pisignage-dev"*');
console.log('* in config/env/development.js and restart the server *');
console.log('******************************************************************\n');
var app = express();
// Express settings
require('./config/express')(app);
// Start server
var server;
if (config.https) {
var https_options = {
ca: fs.readFileSync("/home/ec2-user/.ssh/intermediate.crt"),
key: fs.readFileSync("/home/ec2-user/.ssh/pisignage-server.key"),
cert: fs.readFileSync("/home/ec2-user/.ssh/pisignage-server.crt")
};
server = require('https').createServer(https_options, app);
//require('http').createServer(app).listen(80);
}
else {
server = require('http').createServer(app);
}
var io = oldSocketio.listen(server);
var ioNew = socketio(server,{
path: '/newsocket.io',
serveClient: true,
// below are engine.IO options
pingInterval: 45000,
pingTimeout: 45000,
upgradeTimeout: 60000,
maxHttpBufferSize: 10e7
});
//Bootstrap socket.io
require('./app/controllers/server-socket').startSIO(io);
require('./app/controllers/server-socket-new').startSIO(ioNew);
require('./app/controllers/scheduler');
server.listen(config.port, function () {
console.log('Express server listening on port %d in %s mode', config.port, app.get('env'));
});
server.on('connection', function(socket) {
// 60 minutes timeout
socket.setTimeout(3600000);
});
server.on('error', function (err) {console.log("caught ECONNRESET error 1");console.log(err)});
io.on('error', function (err) {console.log("caught ECONNRESET error 2");console.log(err)});
io.sockets.on('error', function (err) {console.log("caught ECONNRESET error 3");console.log(err)});
ioNew.on('error', function (err) {console.log("caught ECONNRESET error 4");console.log(err)});
ioNew.sockets.on('error', function (err) {console.log("caught ECONNRESET error 5");console.log(err)});
// Expose app
module.exports = app;