-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97fe428
commit d83db4a
Showing
2 changed files
with
41 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,67 @@ | ||
var mongoose = require('mongoose'), http = require('http'), util = require('util'); | ||
var mongoose = require('mongoose'), | ||
http = require('http'), | ||
util = require('util'); | ||
|
||
module.exports.mount = function (config, app) { | ||
module.exports.mount = function(config, app) { | ||
'use strict'; | ||
|
||
//Connect to database | ||
mongoose.connect(config.db.url); | ||
try { | ||
//Connect to database | ||
mongoose.connect(config.db.url); | ||
} | ||
catch (err) { | ||
throw new Error('Unable to connect to MongoDB at ' + config.db.url); | ||
} | ||
finally { | ||
process.exit(); | ||
} | ||
|
||
|
||
|
||
// CONNECTION EVENTS | ||
// When successfully connected | ||
mongoose.connection.on('connected', function () { | ||
// When successfully connected | ||
mongoose.connection.on('connected', function() { | ||
console.log('Mongoose default connection open to ', config.db); | ||
}); | ||
|
||
// If the connection throws an error | ||
mongoose.connection.on('error',function (err) { | ||
// If the connection throws an error | ||
mongoose.connection.on('error', function(err) { | ||
console.log('Mongoose default connection error: ' + err); | ||
}); | ||
|
||
// When the connection is disconnected | ||
mongoose.connection.on('disconnected', function () { | ||
// When the connection is disconnected | ||
mongoose.connection.on('disconnected', function() { | ||
console.log('Mongoose default connection disconnected'); | ||
}); | ||
|
||
// If the Node process ends, close the Mongoose connection | ||
// If the Node process ends, close the Mongoose connection | ||
process.on('SIGINT', function() { | ||
mongoose.connection.close(function () { | ||
mongoose.connection.close(function() { | ||
console.log('Mongoose default connection disconnected through app termination'); | ||
process.exit(0); | ||
}); | ||
}); | ||
|
||
var server = http.createServer(app); | ||
|
||
require( './cms-auth' )( config, app ); | ||
require( './cms-passport' )( config, app ); | ||
require( './cms-rest' )( config, app ); | ||
require( './cms-proxy' )( config, app ); | ||
require( './cms-upload' )( config, app ); | ||
require( './cms-sockets' )( config, server ); | ||
require( './cms-server' )( config, app ); | ||
|
||
var server = http.createServer(app); | ||
|
||
require('./cms-auth')(config, app); | ||
require('./cms-passport')(config, app); | ||
require('./cms-rest')(config, app); | ||
require('./cms-proxy')(config, app); | ||
require('./cms-upload')(config, app); | ||
require('./cms-sockets')(config, server); | ||
require('./cms-server')(config, app); | ||
|
||
|
||
return server.listen(config.port || process.env.PORT, function () { | ||
var serverPort = process.env.PORT || config.port; | ||
var serverHost = process.env.IP || config.host; | ||
|
||
return server.listen(serverPort, serverHost, function() { | ||
util.log('App listening on port: ' + config.port + ''.verbose); | ||
util.log(util.inspect(config, {colors: true})); | ||
util.log(util.inspect(config, { | ||
colors: true | ||
})); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters