mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-11 08:43:59 +03:00
fdefa4964f
- 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
33 lines
908 B
JavaScript
33 lines
908 B
JavaScript
// @TODO: refactor constructor pattern so we don't have to require config here?
|
|
const config = require('./shared/config');
|
|
const {events} = require('./server/lib/common');
|
|
const themeEngine = require('./frontend/services/theme-engine');
|
|
|
|
class Bridge {
|
|
constructor() {
|
|
/**
|
|
* When locale changes, we reload theme translations
|
|
* @deprecated: the term "lang" was deprecated in favour of "locale" publicly 4.0
|
|
*/
|
|
events.on('settings.lang.edited', () => {
|
|
this.getActiveTheme().initI18n();
|
|
});
|
|
}
|
|
|
|
getActiveTheme() {
|
|
return themeEngine.getActive();
|
|
}
|
|
|
|
getFrontendApiVersion() {
|
|
if (this.getActiveTheme()) {
|
|
return this.getActiveTheme().engine('ghost-api');
|
|
} else {
|
|
return config.get('api:versions:default');
|
|
}
|
|
}
|
|
}
|
|
|
|
const bridge = new Bridge();
|
|
|
|
module.exports = bridge;
|