mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Changed express apps to start after migrations
refs #12568 - Allowing express app (frontend) to be booted after the migrations decouples server maintenance mode from a need to have the "frontend" loaded beforehand
This commit is contained in:
parent
a79ed1170d
commit
7e28802b1c
2 changed files with 42 additions and 35 deletions
|
@ -19,12 +19,8 @@ const stoppable = require('stoppable');
|
|||
* ## GhostServer
|
||||
*/
|
||||
class GhostServer {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} rootApp - parent express instance
|
||||
*/
|
||||
constructor(rootApp) {
|
||||
this.rootApp = rootApp;
|
||||
constructor() {
|
||||
this.rootApp = null;
|
||||
this.httpServer = null;
|
||||
|
||||
// Expose config module for use externally.
|
||||
|
|
|
@ -80,33 +80,7 @@ async function initializeRecurringJobs() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* - initialise models
|
||||
* - initialise i18n
|
||||
* - load all settings into settings cache (almost every component makes use of this cache)
|
||||
* - load active theme
|
||||
* - create our express apps (site, admin, api)
|
||||
* - start the ghost server
|
||||
* - enable maintenance mode if migrations are missing
|
||||
*/
|
||||
const minimalRequiredSetupToStartGhost = async (dbState) => {
|
||||
const settings = require('./services/settings');
|
||||
const jobService = require('./services/jobs');
|
||||
const models = require('./models');
|
||||
const GhostServer = require('./ghost-server');
|
||||
|
||||
let ghostServer;
|
||||
|
||||
// Initialize Ghost core internationalization
|
||||
i18n.init();
|
||||
debug('Default i18n done for core');
|
||||
|
||||
models.init();
|
||||
debug('Models done');
|
||||
|
||||
await settings.init();
|
||||
debug('Settings done');
|
||||
|
||||
const initExpressApps = async () => {
|
||||
await frontendSettings.init();
|
||||
debug('Frontend settings done');
|
||||
|
||||
|
@ -116,7 +90,32 @@ const minimalRequiredSetupToStartGhost = async (dbState) => {
|
|||
const parentApp = require('./web/parent/app')();
|
||||
debug('Express Apps done');
|
||||
|
||||
ghostServer = new GhostServer(parentApp);
|
||||
return parentApp;
|
||||
};
|
||||
|
||||
/**
|
||||
* - initialise models
|
||||
* - initialise i18n
|
||||
* - start the ghost server
|
||||
* - load all settings into settings cache (almost every component makes use of this cache)
|
||||
* - enable maintenance mode if migrations are missing
|
||||
* - load active theme
|
||||
* - create our express apps (site, admin, api)
|
||||
*/
|
||||
const minimalRequiredSetupToStartGhost = async (dbState) => {
|
||||
const settings = require('./services/settings');
|
||||
const jobService = require('./services/jobs');
|
||||
const models = require('./models');
|
||||
const GhostServer = require('./ghost-server');
|
||||
|
||||
// Initialize Ghost core internationalization
|
||||
i18n.init();
|
||||
debug('Default i18n done for core');
|
||||
|
||||
models.init();
|
||||
debug('Models done');
|
||||
|
||||
const ghostServer = new GhostServer();
|
||||
|
||||
ghostServer.registerCleanupTask(async () => {
|
||||
await jobService.shutdown();
|
||||
|
@ -124,6 +123,11 @@ const minimalRequiredSetupToStartGhost = async (dbState) => {
|
|||
|
||||
// CASE: all good or db was just initialised
|
||||
if (dbState === 1 || dbState === 2) {
|
||||
await settings.init();
|
||||
debug('Settings done');
|
||||
const parentApp = await initExpressApps();
|
||||
ghostServer.rootApp = parentApp;
|
||||
|
||||
events.emit('db.ready');
|
||||
|
||||
await initialiseServices();
|
||||
|
@ -135,9 +139,16 @@ const minimalRequiredSetupToStartGhost = async (dbState) => {
|
|||
logging.info('Blog is in maintenance mode.');
|
||||
|
||||
try {
|
||||
// const delay= ms => new Promise(resolve => setTimeout(resolve ,ms));
|
||||
await migrator.migrate();
|
||||
|
||||
await settings.reinit();
|
||||
// await delay(10000);
|
||||
await settings.init();
|
||||
debug('Settings done');
|
||||
|
||||
const parentApp = await initExpressApps();
|
||||
ghostServer.rootApp = parentApp;
|
||||
|
||||
events.emit('db.ready');
|
||||
|
||||
await initialiseServices();
|
||||
|
|
Loading…
Reference in a new issue