mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-30 06:12:03 +03:00
0b79abf5b2
Background: - Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow - The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost - With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces This commit: - adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week - Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code - reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else - is missing tests for this new db utility - leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process - doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
// # Ghost Startup
|
|
// Orchestrates the startup of Ghost when run from command line.
|
|
|
|
const startTime = Date.now();
|
|
const debug = require('ghost-ignition').debug('boot:index');
|
|
// Sentry must be initialised early on
|
|
const sentry = require('./core/shared/sentry');
|
|
|
|
debug('First requires...');
|
|
|
|
const ghost = require('./core');
|
|
|
|
debug('Required ghost');
|
|
|
|
const express = require('./core/shared/express');
|
|
const logging = require('./core/shared/logging');
|
|
const urlService = require('./core/frontend/services/url');
|
|
|
|
logging.info('Boot Mode: 3.0');
|
|
// This is what listen gets called on, it needs to be a full Express App
|
|
const ghostApp = express('ghost');
|
|
|
|
// Use the request handler at the top level
|
|
// @TODO: decide if this should be here or in parent App - should it come after request id mw?
|
|
ghostApp.use(sentry.requestHandler);
|
|
|
|
debug('Initialising Ghost');
|
|
|
|
ghost().then(function (ghostServer) {
|
|
// Mount our Ghost instance on our desired subdirectory path if it exists.
|
|
ghostApp.use(urlService.utils.getSubdir(), ghostServer.rootApp);
|
|
|
|
debug('Starting Ghost');
|
|
// Let Ghost handle starting our server instance.
|
|
return ghostServer.start(ghostApp)
|
|
.then(function afterStart() {
|
|
logging.info('Ghost boot', (Date.now() - startTime) / 1000 + 's');
|
|
});
|
|
}).catch(function (err) {
|
|
logging.error(err);
|
|
setTimeout(() => {
|
|
process.exit(-1);
|
|
}, 100);
|
|
});
|