mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Cleaned up global server events
- use theme.ready for loading themes instead of server.start and properly clean this up - remove server.start and server.stop as they are no longer used (only server.start was used, and only for themes) - we're moving away from the pattern of using global events like this as they are hard to reason about
This commit is contained in:
parent
d150516ec3
commit
b1a98b0b67
@ -28,10 +28,6 @@ module.exports = {
|
|||||||
themeLoader.loadAllThemes();
|
themeLoader.loadAllThemes();
|
||||||
});
|
});
|
||||||
|
|
||||||
events.on('themes.ready', function readAllThemesOnServerStart() {
|
|
||||||
themeLoader.loadAllThemes();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Just read the active theme for now
|
// Just read the active theme for now
|
||||||
return themeLoader
|
return themeLoader
|
||||||
.loadOneTheme(activeThemeName)
|
.loadOneTheme(activeThemeName)
|
||||||
|
@ -9,7 +9,7 @@ const _ = require('lodash');
|
|||||||
const config = require('../shared/config');
|
const config = require('../shared/config');
|
||||||
const urlUtils = require('./../shared/url-utils');
|
const urlUtils = require('./../shared/url-utils');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const {events, i18n} = require('./lib/common');
|
const {i18n} = require('./lib/common');
|
||||||
const logging = require('../shared/logging');
|
const logging = require('../shared/logging');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const bootstrapSocket = require('@tryghost/bootstrap-socket');
|
const bootstrapSocket = require('@tryghost/bootstrap-socket');
|
||||||
@ -162,7 +162,6 @@ class GhostServer {
|
|||||||
await this._cleanup();
|
await this._cleanup();
|
||||||
} finally {
|
} finally {
|
||||||
// Wrap up
|
// Wrap up
|
||||||
events.emit('server.stop');
|
|
||||||
this.httpServer = null;
|
this.httpServer = null;
|
||||||
this._logStopMessages();
|
this._logStopMessages();
|
||||||
}
|
}
|
||||||
@ -326,9 +325,6 @@ module.exports.announceServerReadiness = function (error = null) {
|
|||||||
if (error) {
|
if (error) {
|
||||||
message.started = false;
|
message.started = false;
|
||||||
message.error = error;
|
message.error = error;
|
||||||
} else {
|
|
||||||
debug('emit: server.start');
|
|
||||||
events.emit('server.start');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE: IPC communication to the CLI for local process manager
|
// CASE: IPC communication to the CLI for local process manager
|
||||||
|
@ -102,18 +102,5 @@ describe('GhostServer', function () {
|
|||||||
process.send.calledOnce.should.be.true();
|
process.send.calledOnce.should.be.true();
|
||||||
socketStub.calledOnce.should.be.true();
|
socketStub.calledOnce.should.be.true();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends server.start event correctly on success', function () {
|
|
||||||
GhostServer.announceServerReadiness();
|
|
||||||
|
|
||||||
eventSpy.calledOnce.should.be.true();
|
|
||||||
eventSpy.firstCall.args[0].should.eql('server.start');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not send server.start event on failure', function () {
|
|
||||||
GhostServer.announceServerReadiness(new Error('something went wrong'));
|
|
||||||
|
|
||||||
eventSpy.calledOnce.should.be.false();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -209,8 +209,8 @@ const restartModeGhostStart = async () => {
|
|||||||
// @TODO: why does this happen _after_ URL service
|
// @TODO: why does this happen _after_ URL service
|
||||||
web.shared.middlewares.customRedirects.reload();
|
web.shared.middlewares.customRedirects.reload();
|
||||||
|
|
||||||
// Trigger server start, which is ONLY used for theme reload
|
// Trigger themes to load again
|
||||||
events.emit('server.start');
|
events.emit('themes.ready');
|
||||||
};
|
};
|
||||||
|
|
||||||
const bootGhost = async () => {
|
const bootGhost = async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user