Skip to content

Commit

Permalink
added enviorment port
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniespratley committed Dec 17, 2014
1 parent 97fe428 commit d83db4a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
62 changes: 40 additions & 22 deletions routes/cms-routes.js
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
}));
});
};
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ var proxyServer = httpProxy.createServer(options, function(req, res, proxy) {


//Start the proxy server
proxyServer.listen(config.proxy.port);
proxyServer.listen(process.env.PORT, process.env.IP);

0 comments on commit d83db4a

Please sign in to comment.