diff --git a/core/boot.js b/core/boot.js index cdeef7e424..c633fbc193 100644 --- a/core/boot.js +++ b/core/boot.js @@ -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(), diff --git a/core/server/services/redirects/index.js b/core/server/services/redirects/index.js index f7eb690e5f..6f9c9fce4d 100644 --- a/core/server/services/redirects/index.js +++ b/core/server/services/redirects/index.js @@ -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; + } };