Moved bridge into its proper location

- Modules in /shared are supposed to be standalone modules that can be required by the server or frontend
- As the server shouldn't require the frontend, and vice versa, shared modules should require neither
- Otherwise it just becomes a crutch for allowing cross-depenencies, and will create circular dependencies

The Bridge
- The bridge file is not meant to be a crutch sat allowing cross-dependencies, but rather a new component that manages the flow of data
- That data flows from the server/boot process TO the frontend, and should not flow in the other direction
- The management of that flow of data is necessarily hacky at the moment, but over time the architecture here should get clearer and better
- Still, for the time being it will need to handle requiring across components until that architecture matures
- Therefore, it should live in core root, not in core/shared
This commit is contained in:
Hannah Wolfe 2021-04-26 14:38:57 +01:00
parent 1025600ae1
commit fdefa4964f
6 changed files with 8 additions and 8 deletions

View File

@ -143,7 +143,7 @@ async function initServices({config}) {
// 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 bridge = require('./shared/bridge');
const bridge = require('./bridge');
// We pass the frontend API version here, so that the frontend services are slightly less tightly-coupled
routing.bootstrap.start(bridge.getFrontendApiVersion());
const settings = require('./server/services/settings');

View File

@ -1,7 +1,7 @@
// @TODO: refactor constructor pattern so we don't have to require config here?
const config = require('./config');
const {events} = require('../server/lib/common');
const themeEngine = require('../frontend/services/theme-engine');
const config = require('./shared/config');
const {events} = require('./server/lib/common');
const themeEngine = require('./frontend/services/theme-engine');
class Bridge {
constructor() {

View File

@ -2,7 +2,7 @@ const _ = require('lodash');
const debug = require('ghost-ignition').debug('frontend:services:settings:validate');
const {i18n} = require('../proxy');
const errors = require('@tryghost/errors');
const bridge = require('../../../shared/bridge');
const bridge = require('../../../bridge');
const _private = {};
let RESOURCE_CONFIG;

View File

@ -52,7 +52,7 @@ class Resources {
return this.resourceConfig;
}
const bridge = require('../../../shared/bridge');
const bridge = require('../../../bridge');
this.resourcesAPIVersion = bridge.getFrontendApiVersion();
this.resourcesConfig = require(`./configs/${this.resourcesAPIVersion}`);
}

View File

@ -1,5 +1,5 @@
const ghostVersion = require('../../../lib/ghost-version');
const bridge = require('../../../../shared/bridge');
const bridge = require('../../../../bridge');
// ### GhostLocals Middleware
// Expose the standard locals that every request will need to have available

View File

@ -6,7 +6,7 @@ const {URL} = require('url');
const errors = require('@tryghost/errors');
// App requires
const bridge = require('../../../shared/bridge');
const bridge = require('../../../bridge');
const config = require('../../../shared/config');
const constants = require('@tryghost/constants');
const storage = require('../../adapters/storage');