refactor(backend): Trigger webserver events in webserver

We were triggering webserver events in Kernel. This change improves
adherence to separation-of-concerns and ensures event cascading is
working as expected. This also better formalizes the boot sequence.
This commit is contained in:
KernelDeimos 2024-05-09 16:18:57 -04:00
parent 89ac491120
commit d800b12569
3 changed files with 18 additions and 15 deletions

View File

@ -152,17 +152,7 @@ class Kernel extends AdvancedBase {
const { services } = this;
await services.ready;
{
const app = services.get('web-server').app;
app.use(async (req, res, next) => {
req.services = services;
next();
});
await services.emit('boot.services-initialized');
await services.emit('install.middlewares.context-aware', { app });
await services.emit('install.routes', { app });
await services.emit('install.routes-gui', { app });
}
await services.emit('boot.consolidation');
// === END: Initialize Service Registry ===
@ -178,9 +168,8 @@ class Kernel extends AdvancedBase {
});
})();
await services.emit('start.webserver');
await services.emit('ready.webserver');
await services.emit('boot.activation');
await services.emit('boot.ready');
}
}

View File

@ -20,7 +20,7 @@ const { Context } = require("../util/context");
const BaseService = require("./BaseService");
class RefreshAssociationsService extends BaseService {
async ['__on_boot.services-initialized'] () {
async ['__on_boot.consolidation'] () {
const { refresh_associations_cache } = require('../helpers');
await Context.allow_fallback(async () => {

View File

@ -42,6 +42,20 @@ class WebServerService extends BaseService {
morgan: require('morgan'),
};
async ['__on_boot.consolidation'] () {
const app = this.app;
const services = this.services;
await services.emit('install.middlewares.context-aware', { app });
await services.emit('install.routes', { app });
await services.emit('install.routes-gui', { app });
}
async ['__on_boot.activation'] () {
const services = this.services;
await services.emit('start.webserver');
await services.emit('ready.webserver');
}
async ['__on_start.webserver'] () {
await es_import_promise;