Ghost/core/index.js
Harry Wolff 3e21940b18 Add promise to ghost startup process to allow
hooking into when ghost has finished loading

addresses item 9 in #2078
and makes progress on #2182

- has files that startup ghost return a promise
 that is resolved once ghost has finished loading
- moves getSocket into config file
- removes models.reset() as it's not used anywhere
- update functions in server startup
- remove unused version hash variable
2014-03-11 11:41:45 -04:00

32 lines
969 B
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 () {
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);
});
});
return deferred.promise;
}
module.exports = startGhost;