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'),
|
2014-08-14 01:58:12 +04:00
|
|
|
bootstrap = require('./bootstrap'),
|
|
|
|
server = require('./server');
|
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
|
|
|
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 () {
|
2014-05-11 20:33:18 +04:00
|
|
|
try {
|
2014-08-14 01:58:12 +04:00
|
|
|
return server(options.app)
|
2014-05-11 20:33:18 +04:00
|
|
|
.then(deferred.resolve)
|
2014-06-18 04:25:19 +04:00
|
|
|
.catch(function (err) {
|
2014-05-11 20:33:18 +04:00
|
|
|
// We don't return the rejected promise to stop
|
2014-06-12 09:45:20 +04:00
|
|
|
// the propagation of the rejection and just
|
2014-05-11 20:33:18 +04:00
|
|
|
// allow the user to manage what to do.
|
2014-06-18 04:25:19 +04:00
|
|
|
deferred.reject(err);
|
2014-05-11 20:33:18 +04:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2014-02-20 07:22:02 +04:00
|
|
|
deferred.reject(e);
|
2014-05-11 20:33:18 +04:00
|
|
|
}
|
2014-06-18 04:25:19 +04:00
|
|
|
}).catch(deferred.reject);
|
2014-02-20 07:22:02 +04:00
|
|
|
|
|
|
|
return deferred.promise;
|
2013-11-26 07:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = startGhost;
|