-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (46 loc) · 1.59 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'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.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> at <host>
app.listen(config.port, config.host, function () {
// Create server URL
var server = (process.env.NODE_ENV === 'secure' ? 'https://' : 'http://') + config.host + ':' + config.port;
// Logging initialization
console.log('--');
console.log(chalk.green(config.app.title));
console.log();
console.log(chalk.green('Environment: ' + process.env.NODE_ENV));
console.log(chalk.green('Server: ' + server));
console.log(chalk.green('Database: ' + config.db.uri));
console.log(chalk.green('App version: ' + config.meanjs.version));
if (config.meanjs['meanjs-version'])
console.log(chalk.green('MEAN.JS version: ' + config.meanjs['meanjs-version']));
console.log('--');
if (callback) callback(app, db, config);
});
});
};