From fdefa4964f031f8073ee2ee67b6507f033be712a Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 26 Apr 2021 14:38:57 +0100 Subject: [PATCH] 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 --- core/boot.js | 2 +- core/{shared => }/bridge.js | 6 +++--- core/frontend/services/settings/validate.js | 2 +- core/frontend/services/url/Resources.js | 2 +- core/server/web/parent/middleware/ghost-locals.js | 2 +- core/server/web/site/app.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename core/{shared => }/bridge.js (82%) diff --git a/core/boot.js b/core/boot.js index 076ef486e5..00e957c5ac 100644 --- a/core/boot.js +++ b/core/boot.js @@ -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'); diff --git a/core/shared/bridge.js b/core/bridge.js similarity index 82% rename from core/shared/bridge.js rename to core/bridge.js index 8fe139a0fb..d807d4da9d 100644 --- a/core/shared/bridge.js +++ b/core/bridge.js @@ -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() { diff --git a/core/frontend/services/settings/validate.js b/core/frontend/services/settings/validate.js index 7b204c9a33..49b09e1c45 100644 --- a/core/frontend/services/settings/validate.js +++ b/core/frontend/services/settings/validate.js @@ -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; diff --git a/core/frontend/services/url/Resources.js b/core/frontend/services/url/Resources.js index 8e37954809..b3f66adb84 100644 --- a/core/frontend/services/url/Resources.js +++ b/core/frontend/services/url/Resources.js @@ -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}`); } diff --git a/core/server/web/parent/middleware/ghost-locals.js b/core/server/web/parent/middleware/ghost-locals.js index ea70f00157..6d66c359f1 100644 --- a/core/server/web/parent/middleware/ghost-locals.js +++ b/core/server/web/parent/middleware/ghost-locals.js @@ -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 diff --git a/core/server/web/site/app.js b/core/server/web/site/app.js index e6489530a3..1a7dc5a6ae 100644 --- a/core/server/web/site/app.js +++ b/core/server/web/site/app.js @@ -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');