2013-11-25 22:22:59 -05:00
|
|
|
// # Ghost bootloader
|
|
|
|
// Orchestrates the loading of Ghost
|
|
|
|
// When run from command line.
|
|
|
|
|
2014-02-19 22:22:02 -05:00
|
|
|
var when = require('when'),
|
2014-08-13 16:58:12 -05:00
|
|
|
bootstrap = require('./bootstrap'),
|
|
|
|
server = require('./server');
|
2013-11-25 22:22:59 -05:00
|
|
|
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
2014-08-19 11:36:46 -05:00
|
|
|
function makeGhost(options) {
|
2014-02-19 22:22:02 -05:00
|
|
|
var deferred = when.defer();
|
|
|
|
|
2014-02-08 10:41:15 -05:00
|
|
|
options = options || {};
|
2014-02-19 22:22:02 -05:00
|
|
|
|
2014-02-08 10:41:15 -05:00
|
|
|
bootstrap(options.config).then(function () {
|
2014-05-11 11:33:18 -05:00
|
|
|
try {
|
2014-08-13 16:58:12 -05:00
|
|
|
return server(options.app)
|
2014-05-11 11:33:18 -05:00
|
|
|
.then(deferred.resolve)
|
2014-06-17 19:25:19 -05:00
|
|
|
.catch(function (err) {
|
2014-05-11 11:33:18 -05:00
|
|
|
// We don't return the rejected promise to stop
|
2014-06-12 00:45:20 -05:00
|
|
|
// the propagation of the rejection and just
|
2014-05-11 11:33:18 -05:00
|
|
|
// allow the user to manage what to do.
|
2014-06-17 19:25:19 -05:00
|
|
|
deferred.reject(err);
|
2014-05-11 11:33:18 -05:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2014-02-19 22:22:02 -05:00
|
|
|
deferred.reject(e);
|
2014-05-11 11:33:18 -05:00
|
|
|
}
|
2014-06-17 19:25:19 -05:00
|
|
|
}).catch(deferred.reject);
|
2014-02-19 22:22:02 -05:00
|
|
|
|
|
|
|
return deferred.promise;
|
2013-11-25 22:22:59 -05:00
|
|
|
}
|
|
|
|
|
2014-08-19 11:36:46 -05:00
|
|
|
module.exports = makeGhost;
|