Ghost/index.js
Hannah Wolfe 9bd50cb527 ⏱ Boot time visibility amends (#7984)
refs #2182

* ⏱ Add boot timer - improve visibility of boot time

I've been playing around with Ghost start times a lot recently.
Every time I do, I add a console.time output for boot, which is annoying.
This commit adds that change permanently. We can always revert later before shipping 1.0 😁

* ⏱ Add debug call before main requires

- this demonstrates that the majority of boot time is spent on requires
- had to rejig the var pattern because of the linter... 💩

* 🐷 💄 Special debug mode for config

- I ❤️  being able to output the config, but this is not useful when trying to debug / optimise timings.
- This change makes it so we can see how long it takes to do config work by default
- If we want to output config specifically, we do `DEBUG=ghost:*,ghost-config npm start`
- This also prevents nconf.get() from being called unnecessarily
2017-02-17 16:27:02 +01:00

47 lines
1.3 KiB
JavaScript

// # Ghost Startup
// Orchestrates the startup of Ghost when run from command line.
console.time('Ghost boot');
var debug = require('debug')('ghost:boot:index'),
ghost, express, logging, errors, utils, parentApp;
debug('First requires...');
ghost = require('./core');
debug('Required ghost');
express = require('express');
logging = require('./core/server/logging');
errors = require('./core/server/errors');
utils = require('./core/server/utils');
parentApp = express();
debug('Initialising Ghost');
ghost().then(function (ghostServer) {
// Mount our Ghost instance on our desired subdirectory path if it exists.
parentApp.use(utils.url.getSubdir(), ghostServer.rootApp);
debug('Starting Ghost');
// Let Ghost handle starting our server instance.
return ghostServer.start(parentApp).then(function afterStart() {
console.timeEnd('Ghost boot');
// if IPC messaging is enabled, ensure ghost sends message to parent
// process on successful start
if (process.send) {
process.send({started: true});
}
});
}).catch(function (err) {
if (!errors.utils.isIgnitionError(err)) {
err = new errors.GhostError({err: err});
}
if (process.send) {
process.send({started: false, error: err.message});
}
logging.error(err);
process.exit(-1);
});