From 9163c48f4e20b38137ae848783b5d54a80e3b32c Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 27 Jan 2021 12:16:00 +1300 Subject: [PATCH] Refactored minimal setup for Ghost boot refs #12568 - Moved duplicated initialization code to make initialization stages clearer --- core/server/index.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/server/index.js b/core/server/index.js index fb4ffdf63e..f8b654ade8 100644 --- a/core/server/index.js +++ b/core/server/index.js @@ -16,7 +16,6 @@ const {events, i18n} = require('./lib/common'); const logging = require('../shared/logging'); const migrator = require('./data/db/migrator'); const urlUtils = require('./../shared/url-utils'); -let parentApp; // Frontend Components const themeService = require('../frontend/services/themes'); @@ -114,7 +113,7 @@ const minimalRequiredSetupToStartGhost = async (dbState) => { await themeService.init(); debug('Themes done'); - parentApp = require('./web/parent/app')(); + const parentApp = require('./web/parent/app')(); debug('Express Apps done'); ghostServer = new GhostServer(parentApp); @@ -128,15 +127,12 @@ const minimalRequiredSetupToStartGhost = async (dbState) => { events.emit('db.ready'); await initialiseServices(); - initializeRecurringJobs(); - return ghostServer; } // CASE: migrations required, put blog into maintenance mode if (dbState === 4) { - logging.info('Blog is in maintenance mode.'); - config.set('maintenance:enabled', true); + logging.info('Blog is in maintenance mode.'); try { await migrator.migrate(); @@ -150,10 +146,6 @@ const minimalRequiredSetupToStartGhost = async (dbState) => { logging.info('Blog is out of maintenance mode.'); await GhostServer.announceServerReadiness(); - - initializeRecurringJobs(); - - return ghostServer; } catch (err) { try { await GhostServer.announceServerReadiness(err); @@ -165,6 +157,10 @@ const minimalRequiredSetupToStartGhost = async (dbState) => { } } } + + initializeRecurringJobs(); + + return ghostServer; }; /**