From c44e33b1f7a1c835d4e720caa0ac39d425730a0e Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 12 Oct 2021 17:21:29 +0200 Subject: [PATCH] Simplified DynamicRedirectManager's constructor interface refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch - There is no need to pass in whole "urlUtils" instance to construct the class as all the class has to know is how to construct a "subdirectory URL" which can be a single function passed in instead of a vague object instance --- .../lib/DynamicRedirectManager.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ghost/express-dynamic-redirects/lib/DynamicRedirectManager.js b/ghost/express-dynamic-redirects/lib/DynamicRedirectManager.js index cb45386bbc..34304710ad 100644 --- a/ghost/express-dynamic-redirects/lib/DynamicRedirectManager.js +++ b/ghost/express-dynamic-redirects/lib/DynamicRedirectManager.js @@ -6,13 +6,14 @@ class DynamicRedirectManager { /** * @param {object} config * @param {number} config.permanentMaxAge - * @param {object} config.urlUtils + * @param {function} config.getSubdirectoryURL */ - constructor({permanentMaxAge, urlUtils}) { + constructor({permanentMaxAge, getSubdirectoryURL}) { /** @private */ this.permanentMaxAge = permanentMaxAge; - /** @private */ - this.urlUtils = urlUtils; + + this.getSubdirectoryURL = getSubdirectoryURL; + /** @private */ this.router = express.Router(); /** @private @type {string[]} */ @@ -72,7 +73,7 @@ class DynamicRedirectManager { * @see https://github.com/TryGhost/Ghost/issues/10776 */ if (!toURL.hostname) { - toURL.pathname = this.urlUtils.urlJoin(this.urlUtils.getSubdir(), toURL.pathname); + toURL.pathname = this.getSubdirectoryURL(toURL.pathname); } res.set({