0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Moved custom redirects initialization to frontend init secton

refs https://github.com/TryGhost/Toolbox/issues/139

- The custom redirects services belong in the  initServicesForFrontend because frontend depends on these to function properly. When placed in general init section the middleware would not get initialized properly before it's used by the "frontend express app"
This commit is contained in:
Naz 2021-11-25 12:52:01 +04:00 committed by naz
parent fd0a0ddf47
commit e6c9bcdf22
2 changed files with 16 additions and 10 deletions

View file

@ -131,6 +131,11 @@ async function initServicesForFrontend() {
await routeSettings.init();
debug('End: Routing Settings');
debug('Begin: Redirects');
const customRedirects = require('./server/services/redirects');
await customRedirects.init(),
debug('End: Redirects');
debug('Begin: Themes');
// customThemSettingsService.api must be initialized before any theme activation occurs
const customThemeSettingsService = require('./server/services/custom-theme-settings');
@ -222,7 +227,6 @@ async function initServices({config}) {
const appService = require('./frontend/services/apps');
const limits = require('./server/services/limits');
const scheduling = require('./server/adapters/scheduling');
const customRedirects = require('./server/services/redirects');
const urlUtils = require('./shared/url-utils');
@ -236,7 +240,6 @@ async function initServices({config}) {
await offers.init();
await Promise.all([
customRedirects.init(),
members.init(),
permissions.init(),
xmlrpc.listen(),

View file

@ -4,17 +4,18 @@ const urlUtils = require('../../../shared/url-utils');
const DynamicRedirectManager = require('@tryghost/express-dynamic-redirects');
const CustomRedirectsAPI = require('./api');
const redirectManager = new DynamicRedirectManager({
permanentMaxAge: config.get('caching:customRedirects:maxAge'),
getSubdirectoryURL: (pathname) => {
return urlUtils.urlJoin(urlUtils.getSubdir(), pathname);
}
});
let customRedirectsAPI;
let redirectManager;
module.exports = {
init() {
redirectManager = new DynamicRedirectManager({
permanentMaxAge: config.get('caching:customRedirects:maxAge'),
getSubdirectoryURL: (pathname) => {
return urlUtils.urlJoin(urlUtils.getSubdir(), pathname);
}
});
customRedirectsAPI = new CustomRedirectsAPI({
basePath: config.getContentPath('data'),
redirectManager
@ -27,5 +28,7 @@ module.exports = {
return customRedirectsAPI;
},
middleware: redirectManager.handleRequest
get middleware() {
return redirectManager.handleRequest;
}
};