2013-11-26 07:22:59 +04:00
|
|
|
// # Ghost bootloader
|
|
|
|
// Orchestrates the loading of Ghost
|
|
|
|
// When run from command line.
|
|
|
|
|
2014-02-20 07:22:02 +04:00
|
|
|
var when = require('when'),
|
|
|
|
bootstrap = require('./bootstrap');
|
2013-11-26 07:22:59 +04:00
|
|
|
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
2014-02-08 19:41:15 +04:00
|
|
|
function startGhost(options) {
|
2014-02-20 07:22:02 +04:00
|
|
|
// When we no longer need to require('./server')
|
|
|
|
// in a callback this extra deferred object
|
|
|
|
// won't be necessary, we'll just be able to return
|
|
|
|
// the server object directly.
|
|
|
|
var deferred = when.defer();
|
|
|
|
|
2014-02-08 19:41:15 +04:00
|
|
|
options = options || {};
|
2014-02-20 07:22:02 +04:00
|
|
|
|
2014-02-08 19:41:15 +04:00
|
|
|
bootstrap(options.config).then(function () {
|
2013-11-26 07:22:59 +04:00
|
|
|
var ghost = require('./server');
|
2014-02-20 07:22:02 +04:00
|
|
|
return ghost(options.app).then(deferred.resolve).otherwise(function (e) {
|
|
|
|
// We don't return the rejected promise to stop
|
|
|
|
// the propogation of the rejection and just
|
|
|
|
// allow the user to manage what to do.
|
|
|
|
deferred.reject(e);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
2013-11-26 07:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = startGhost;
|