0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/core/server/services/route-settings/index.js
Naz cbec6aa49e Refactored route settings module into class
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- It's a step to making the module follow class+DI pattern before fully extracting it into an external libarary
- Reminder, doing in Ghost repo instead of substituting big chunks all at once to have clear history of how the service evolved prior to the extraction into external lib!
2021-11-24 05:32:20 +13:00

37 lines
1.2 KiB
JavaScript

const RouteSettings = require('./route-settings');
const SettingsLoader = require('./settings-loader');
const config = require('../../../shared/config');
const parseYaml = require('./yaml-parser');
const DefaultSettingsManager = require('./default-settings-manager');
const defaultSettingsManager = new DefaultSettingsManager({
type: 'routes',
extension: '.yaml',
destinationFolderPath: config.getContentPath('settings'),
sourceFolderPath: config.get('paths').defaultSettings
});
const settingsLoader = new SettingsLoader({
parseYaml,
storageFolderPath: config.getContentPath('settings')
});
const routeSettings = new RouteSettings();
module.exports = {
init: async () => {
return await defaultSettingsManager.ensureSettingsFileExists();
},
loadRouteSettingsSync: settingsLoader.loadSettingsSync.bind(settingsLoader),
loadRouteSettings: settingsLoader.loadSettings.bind(settingsLoader),
getDefaultHash: routeSettings.getDefaultHash.bind(routeSettings),
/**
* Methods used in the API
*/
api: {
setFromFilePath: routeSettings.setFromFilePath.bind(routeSettings),
get: routeSettings.get.bind(routeSettings),
getCurrentHash: routeSettings.getCurrentHash.bind(routeSettings)
}
};