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
This commit is contained in:
Naz 2021-10-12 17:21:29 +02:00
parent ba2a5df493
commit c44e33b1f7

View File

@ -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({