-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·80 lines (64 loc) · 2.24 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
'use strict';
/**
* @namespace Node
*/
/*
Module dependencies.
*/
var BluebirdPromise = require('bluebird');
BluebirdPromise.longStackTraces();
var init = require('./config/init')();
var config = require('./config/config');
var mongoose = BluebirdPromise.promisifyAll(require('mongoose'));
var http = BluebirdPromise.promisifyAll(require('http'));
var execFile = require('child_process').execFile;
// Require the logging module in all environments but test
//if (process.env.NODE_ENV !== 'test') {
require('./config/logging');
//}
/*
Main application entry file.
Please note that the order of loading is important.
*/
var app, server;
// Instead of exporting the app as we did before, export a promise. On
// resolution, the handler for this promise will be passed the started app.
exports = module.exports = mongoose.connectAsync(config.db)
.then(function() {
console.log('EIM application starting');
console.log('Connected to database');
app = require('./config/express')();
console.log('Started Express server');
})
.then(function() {
return http.createServer(app);
})
.then(function(createdServer) {
server = createdServer;
return server.listenAsync(config.port);
})
.then(function() {
// Require OSC
require('./app/controllers/osc').init();
console.log('Initialized OSC');
// Fire up SocketIO
var socket = require('./app/controllers/socket');
socket.init(server);
console.log('Initialized Socket.IO');
// Expose app--see above comment about exporting a promise instead
//exports = module.exports = app;
// Logging initialization
console.log('EIM application successfully started on port ' +
config.port);
// FIXME: This is hacky sh*t
// If we are in production mode, try and open Chrome
if (process.env.NODE_ENV === 'production') {
var chrome = 'C:\\Program' +
' Files\\Google\\Chrome\\Application\\chrome.exe';
execFile(chrome, ['--kiosk', 'http://localhost:3000']);
}
return app;
})
.catch(function(e) {
console.error('Error starting EIM application: ' + e.message);
});