This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring server application service to enable modularity and callb…
…acks, as well as provide app, db, config variables outside of server.js
- Loading branch information
Showing
4 changed files
with
71 additions
and
36 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
var config = require('../config'), | ||
mongoose = require('./mongoose'), | ||
express = require('./express'), | ||
chalk = require('chalk'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
// Initialize Models | ||
mongoose.loadModels(); | ||
|
||
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('--'); | ||
|
||
if (callback) callback(app, db, config); | ||
}); | ||
|
||
}); | ||
|
||
}; |
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
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
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
//creating section