2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
2016-05-20 21:11:37 +00:00
|
|
|
|
|
|
|
//Load ENV vars from .env
|
|
|
|
require('dotenv').config();
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
var init = require('./config/init')(),
|
|
|
|
config = require('./config/config'),
|
|
|
|
mongoose = require('mongoose'),
|
|
|
|
chalk = require('chalk');
|
|
|
|
|
2016-05-20 21:11:37 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
/**
|
|
|
|
* Main application entry file.
|
|
|
|
* Please note that the order of loading is important.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Bootstrap db connection
|
|
|
|
var db = mongoose.connect(config.db.uri, config.db.options, function(err) {
|
|
|
|
if (err) {
|
|
|
|
console.error(chalk.red('Could not connect to MongoDB!'));
|
|
|
|
console.log(chalk.red(err));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mongoose.connection.on('error', function(err) {
|
|
|
|
console.error(chalk.red('MongoDB connection error: ' + err));
|
|
|
|
process.exit(-1);
|
2015-08-11 20:32:27 +00:00
|
|
|
});
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
// Init the express application
|
|
|
|
var app = require('./config/express')(db);
|
|
|
|
|
|
|
|
// Bootstrap passport config
|
|
|
|
require('./config/passport')();
|
|
|
|
|
|
|
|
// Start the app by listening on <port>
|
|
|
|
app.listen(config.port);
|
|
|
|
|
|
|
|
// Expose app
|
|
|
|
exports = module.exports = app;
|
|
|
|
|
|
|
|
// Logging initialization
|
|
|
|
console.log('--');
|
|
|
|
console.log(chalk.green(config.app.title + ' application started'));
|
|
|
|
console.log(chalk.green('Environment:\t\t\t' + process.env.NODE_ENV));
|
|
|
|
console.log(chalk.green('Port:\t\t\t\t' + config.port));
|
|
|
|
console.log(chalk.green('Database:\t\t\t' + config.db.uri));
|
|
|
|
if (process.env.NODE_ENV === 'secure') {
|
|
|
|
console.log(chalk.green('HTTPs:\t\t\t\ton'));
|
|
|
|
}
|
|
|
|
console.log('--');
|
2016-05-20 20:28:27 +00:00
|
|
|
|
|
|
|
process.on('uncaughtException', function (err) {
|
2016-06-04 07:00:31 +00:00
|
|
|
console.error((new Date()).toUTCString() + ' uncaughtException:', err.message);
|
2016-05-20 20:28:27 +00:00
|
|
|
console.error(err.stack);
|
2016-05-20 21:11:37 +00:00
|
|
|
process.exit(1);
|
2016-05-20 20:28:27 +00:00
|
|
|
});
|