Files
meanTorrent/config/lib/app.js
mleanos 28f1f57a26 [hotfix] SeedDB missing in env config
Adds a check for the existence of the seedDB config setting, before
attempting to read config.seedDB.seed setting.

Solves the problem when the seedDB config setting is missing from a
environment config, that causes the application to throw an exception at
startup.

Also, adds the seedDB setting to the Cloud-Foundry env config.
2015-10-28 14:21:11 -07:00

63 lines
1.6 KiB
JavaScript

'use strict';
/**
* Module dependencies.
*/
var config = require('../config'),
mongoose = require('./mongoose'),
express = require('./express'),
chalk = require('chalk'),
seed = require('./seed');
function seedDB() {
if (config.seedDB && config.seedDB.seed) {
console.log(chalk.bold.red('Warning: Database seeding is turned on'));
seed.start();
}
}
// Initialize Models
mongoose.loadModels(seedDB);
module.exports.loadModels = function loadModels() {
mongoose.loadModels();
};
module.exports.init = function init(callback) {
mongoose.connect(function (db) {
// Initialize express
var app = express.init(db);
if (callback) callback(app, db, config);
});
};
module.exports.start = function start(callback) {
var _this = this;
_this.init(function (app, db, config) {
// Start the app by listening on <port>
app.listen(config.port, function () {
// Logging initialization
console.log('--');
console.log(chalk.green(config.app.title));
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\t' + config.db.uri));
if (process.env.NODE_ENV === 'secure') {
console.log(chalk.green('HTTPs:\t\t\t\ton'));
}
console.log(chalk.green('App version:\t\t\t' + config.meanjs.version));
if (config.meanjs['meanjs-version'])
console.log(chalk.green('MEAN.JS version:\t\t\t' + config.meanjs['meanjs-version']));
console.log('--');
if (callback) callback(app, db, config);
});
});
};