mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
Cleaned comments in boot.js
- Cleaned up some of the comments - Added proper method signatures where appropriate - Split initDynamicRouting out from initServices, to make that clearer to read
This commit is contained in:
parent
218df4b5a4
commit
081d3b3a38
59
core/boot.js
59
core/boot.js
@ -4,15 +4,18 @@
|
|||||||
// - This file is FULL of debug statements so we can see timings for the various steps because the boot needs to be as fast as possible
|
// - This file is FULL of debug statements so we can see timings for the various steps because the boot needs to be as fast as possible
|
||||||
// - As we manage to break the codebase down into distinct components for e.g. the frontend, their boot logic can be offloaded to them
|
// - As we manage to break the codebase down into distinct components for e.g. the frontend, their boot logic can be offloaded to them
|
||||||
// - app.js is separate as the first example of each component having it's own app.js file colocated with it, instead of inside of server/web
|
// - app.js is separate as the first example of each component having it's own app.js file colocated with it, instead of inside of server/web
|
||||||
|
//
|
||||||
// IMPORTANT: The only global requires here should be overrides + debug so we can monitor timings with DEBUG=ghost:boot* node ghost
|
// IMPORTANT:
|
||||||
|
// ----------
|
||||||
|
// The only global requires here should be overrides + debug so we can monitor timings with DEBUG = ghost: boot * node ghost
|
||||||
require('./server/overrides');
|
require('./server/overrides');
|
||||||
const debug = require('@tryghost/debug')('boot');
|
const debug = require('@tryghost/debug')('boot');
|
||||||
// END OF GLOBAL REQUIRES
|
// END OF GLOBAL REQUIRES
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to create consistent log messages
|
* Helper class to create consistent log messages
|
||||||
*/class BootLogger {
|
*/
|
||||||
|
class BootLogger {
|
||||||
constructor(logging, startTime) {
|
constructor(logging, startTime) {
|
||||||
this.logging = logging;
|
this.logging = logging;
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
@ -25,6 +28,7 @@ const debug = require('@tryghost/debug')('boot');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to handle sending server ready notifications
|
* Helper function to handle sending server ready notifications
|
||||||
|
* @param {string} [error]
|
||||||
*/
|
*/
|
||||||
function notifyServerReady(error) {
|
function notifyServerReady(error) {
|
||||||
const notify = require('./server/notify');
|
const notify = require('./server/notify');
|
||||||
@ -42,6 +46,10 @@ function notifyServerReady(error) {
|
|||||||
* Get the Database into a ready state
|
* Get the Database into a ready state
|
||||||
* - DatabaseStateManager handles doing all this for us
|
* - DatabaseStateManager handles doing all this for us
|
||||||
* - Passing logging makes it output state messages
|
* - Passing logging makes it output state messages
|
||||||
|
*
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} options.config
|
||||||
|
* @param {object} options.logging
|
||||||
*/
|
*/
|
||||||
async function initDatabase({config, logging}) {
|
async function initDatabase({config, logging}) {
|
||||||
const DatabaseStateManager = require('./server/data/db/state-manager');
|
const DatabaseStateManager = require('./server/data/db/state-manager');
|
||||||
@ -52,6 +60,8 @@ async function initDatabase({config, logging}) {
|
|||||||
/**
|
/**
|
||||||
* Core is intended to be all the bits of Ghost that are fundamental and we can't do anything without them!
|
* Core is intended to be all the bits of Ghost that are fundamental and we can't do anything without them!
|
||||||
* (There's more to do to make this true)
|
* (There's more to do to make this true)
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} options.ghostServer
|
||||||
*/
|
*/
|
||||||
async function initCore({ghostServer}) {
|
async function initCore({ghostServer}) {
|
||||||
debug('Begin: initCore');
|
debug('Begin: initCore');
|
||||||
@ -120,21 +130,13 @@ async function initExpressApps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services are components that make up part of Ghost and need initialising on boot
|
* Dynamic routing is generated from the routes.yaml file, which is part of the settings service
|
||||||
* These services should all be part of core, frontend services should be loaded with the frontend
|
* When Ghost's DB and core are loaded, we can access this file and call routing.bootstrap.start
|
||||||
* We are working towards this being a service loader, with the ability to make certain services optional
|
* However this _must_ happen after the express Apps are loaded, hence why this is here and not in initFrontend
|
||||||
|
* Routing is currently tightly coupled between the frontend and backend
|
||||||
*/
|
*/
|
||||||
async function initServices({config}) {
|
async function initDynamicRouting() {
|
||||||
debug('Begin: initServices');
|
|
||||||
|
|
||||||
const defaultApiVersion = config.get('api:versions:default');
|
|
||||||
debug(`Default API Version: ${defaultApiVersion}`);
|
|
||||||
|
|
||||||
debug('Begin: Dynamic Routing');
|
debug('Begin: Dynamic Routing');
|
||||||
// Dynamic routing is generated from the routes.yaml file, which is part of the settings service
|
|
||||||
// When Ghost's DB and core are loaded, we can access this file and call routing.bootstrap.start
|
|
||||||
// However this _must_ happen after the express Apps are loaded, hence why this is here and not in initFrontend
|
|
||||||
// Routing is currently tightly coupled between the frontend and backend
|
|
||||||
const routing = require('./frontend/services/routing');
|
const routing = require('./frontend/services/routing');
|
||||||
const bridge = require('./bridge');
|
const bridge = require('./bridge');
|
||||||
// We pass the frontend API version here, so that the frontend services are slightly less tightly-coupled
|
// We pass the frontend API version here, so that the frontend services are slightly less tightly-coupled
|
||||||
@ -144,6 +146,21 @@ async function initServices({config}) {
|
|||||||
const getRoutesHash = () => frontendSettings.getCurrentHash('routes');
|
const getRoutesHash = () => frontendSettings.getCurrentHash('routes');
|
||||||
await settings.syncRoutesHash(getRoutesHash);
|
await settings.syncRoutesHash(getRoutesHash);
|
||||||
debug('End: Dynamic Routing');
|
debug('End: Dynamic Routing');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services are components that make up part of Ghost and need initialising on boot
|
||||||
|
* These services should all be part of core, frontend services should be loaded with the frontend
|
||||||
|
* We are working towards this being a service loader, with the ability to make certain services optional
|
||||||
|
*
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} options.config
|
||||||
|
*/
|
||||||
|
async function initServices({config}) {
|
||||||
|
debug('Begin: initServices');
|
||||||
|
|
||||||
|
const defaultApiVersion = config.get('api:versions:default');
|
||||||
|
debug(`Default API Version: ${defaultApiVersion}`);
|
||||||
|
|
||||||
debug('Begin: Services');
|
debug('Begin: Services');
|
||||||
const members = require('./server/services/members');
|
const members = require('./server/services/members');
|
||||||
@ -187,7 +204,10 @@ async function initServices({config}) {
|
|||||||
/**
|
/**
|
||||||
* Kick off recurring jobs and background services
|
* Kick off recurring jobs and background services
|
||||||
* These are things that happen on boot, but we don't need to wait for them to finish
|
* These are things that happen on boot, but we don't need to wait for them to finish
|
||||||
* Later, this might be a service hook
|
* Later, this might be a service hook:q
|
||||||
|
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} options.config
|
||||||
*/
|
*/
|
||||||
async function initBackgroundServices({config}) {
|
async function initBackgroundServices({config}) {
|
||||||
debug('Begin: initBackgroundServices');
|
debug('Begin: initBackgroundServices');
|
||||||
@ -220,6 +240,8 @@ async function initBackgroundServices({config}) {
|
|||||||
*
|
*
|
||||||
* - This function is written with async/await so you can read, line by line, what happens on boot
|
* - This function is written with async/await so you can read, line by line, what happens on boot
|
||||||
* - All the functions above handle init/boot logic for a single component
|
* - All the functions above handle init/boot logic for a single component
|
||||||
|
|
||||||
|
* @returns {Promise<object>} ghostServer
|
||||||
*/
|
*/
|
||||||
async function bootGhost() {
|
async function bootGhost() {
|
||||||
// Metrics
|
// Metrics
|
||||||
@ -294,7 +316,8 @@ async function bootGhost() {
|
|||||||
debug('Begin: Load Ghost Services & Apps');
|
debug('Begin: Load Ghost Services & Apps');
|
||||||
await initCore({ghostServer});
|
await initCore({ghostServer});
|
||||||
await initFrontend();
|
await initFrontend();
|
||||||
const ghostApp = await initExpressApps({});
|
const ghostApp = await initExpressApps();
|
||||||
|
await initDynamicRouting();
|
||||||
await initServices({config});
|
await initServices({config});
|
||||||
debug('End: Load Ghost Services & Apps');
|
debug('End: Load Ghost Services & Apps');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user