-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinit.js
34 lines (31 loc) · 1.04 KB
/
init.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
var config = require('getconfig');
var express = require('express');
var mongoose = require('mongoose');
var queue = require('./app/server/modules/queue');
module.exports = function(ready) {
var app = express();
queue.connect(function(err) {
if (err) throw err;
console.log('Queue connection established');
});
app.root = __dirname;
require('./app/server/setup')(app, express);
require('./app/server/router')(app);
var server = null;
mongoose.connect(config.mongo);
mongoose.connection.on('error', function(error) {
console.log('MONGOOSE ERROR', error);
});
mongoose.connection.once('open', function() {
mongoose.set('debug', true);
console.log(config.mongo);
server = app.listen(config.port, config.host, function(){
console.log('Express server listening on ' + config.host + ':' + config.port);
// Needed for unit tests and wherever we need to embed the app
app._mongoose = mongoose;
if (ready !== null && typeof ready === 'function') {
ready(app, server);
}
});
});
};