0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Moved route settings initialization to backend

refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- Actions logic related to file system operations (like ensuring files exist) should be done on the backend. The frontend will be receiving a unified JSON blob config without needing to know about filesystem
This commit is contained in:
Naz 2021-09-23 18:17:46 +02:00 committed by naz
parent e9c1aff418
commit 31e9434466
6 changed files with 18 additions and 18 deletions

View file

@ -112,10 +112,10 @@ async function initCore({ghostServer, config}) {
async function initFrontend() {
debug('Begin: initFrontend');
debug('Begin: Frontend Settings');
const frontendSettings = require('./frontend/services/settings');
await frontendSettings.init();
debug('End: Frontend Settings');
debug('Begin: Frontend Routing Settings');
const routeSettings = require('./server/services/route-settings');
await routeSettings.init();
debug('End: Frontend Routing Settings');
debug('Begin: Themes');
const themeService = require('./server/services/themes');

View file

@ -1,7 +1,5 @@
const crypto = require('crypto');
const debug = require('@tryghost/debug')('frontend:services:settings:index');
const SettingsLoader = require('./loader');
const ensureSettingsFile = require('./ensure-settings');
/**
* md5 hashes of default routes settings
@ -15,14 +13,6 @@ const calculateHash = (data) => {
};
module.exports = {
init: function () {
debug('init routes settings service');
// Make sure that supported settings files are available
// inside of the `content/setting` directory
return ensureSettingsFile('routes.yaml');
},
/**
* Getter for routes YAML setting.
* Example: `settings.get().then(...)`

View file

@ -9,6 +9,7 @@ const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const config = require('../../../shared/config');
const bridge = require('../../../bridge');
const ensureSettingsFile = require('./ensure-settings');
const messages = {
loadError: 'Could not load {filename} file.'
@ -134,5 +135,14 @@ const get = async () => {
return readFile(settingsFilePath);
};
const init = function () {
debug('init routes settings service');
// Make sure that supported settings files are available
// inside of the `content/setting` directory
return ensureSettingsFile('routes.yaml');
};
module.exports.setFromFilePath = setFromFilePath;
module.exports.get = get;
module.exports.init = init;

View file

@ -3,7 +3,7 @@ const should = require('should');
const fs = require('fs-extra');
const path = require('path');
const configUtils = require('../../../utils/configUtils');
const ensureSettings = require('../../../../core/frontend/services/settings/ensure-settings');
const ensureSettings = require('../../../../core/server/services/route-settings/ensure-settings');
describe('UNIT > Settings Service ensure settings:', function () {
beforeEach(function () {

View file

@ -16,7 +16,7 @@ const db = require('../../core/server/data/db');
const models = require('../../core/server/models');
const urlService = require('../../core/frontend/services/url');
const settingsService = require('../../core/server/services/settings');
const frontendSettingsService = require('../../core/frontend/services/settings');
const routeSettingsService = require('../../core/server/services/route-settings');
const web = require('../../core/server/web');
const themeService = require('../../core/server/services/themes');
const limits = require('../../core/server/services/limits');
@ -109,8 +109,8 @@ const restartModeGhostStart = async () => {
await settingsService.init();
debug('settings done');
// Reload the frontend
await frontendSettingsService.init();
// Load the frontend-related components
await routeSettingsService.init();
await themeService.init();
debug('frontend done');