Ghost/core/index.js
Hannah Wolfe 31b693da1f Add try-catch to startup
- Should prevent Ghost from exiting without an error message
2014-05-11 17:33:18 +01:00

38 lines
1.1 KiB
JavaScript

// # Ghost bootloader
// Orchestrates the loading of Ghost
// When run from command line.
var when = require('when'),
bootstrap = require('./bootstrap');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
function startGhost(options) {
// 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();
options = options || {};
bootstrap(options.config).then(function () {
try {
var ghost = require('./server');
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);
});
} catch (e) {
deferred.reject(e);
}
});
return deferred.promise;
}
module.exports = startGhost;