mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Simplified DynamicRedirectManager's constructor interface
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch
- In most of the packages we follow the pattern of passing in a single "options" object into a constructor and desructuring those the object into parameter, like this example: 077c83dc2d/packages/limit-service/lib/limit-service.js (L19-L26)
This commit is contained in:
parent
73e11690c1
commit
80f2a001ec
2 changed files with 7 additions and 6 deletions
|
@ -6,10 +6,11 @@ class DynamicRedirectManager {
|
||||||
/**
|
/**
|
||||||
* @param {object} config
|
* @param {object} config
|
||||||
* @param {number} config.permanentMaxAge
|
* @param {number} config.permanentMaxAge
|
||||||
|
* @param {object} config.urlUtils
|
||||||
*/
|
*/
|
||||||
constructor(config, urlUtils) {
|
constructor({permanentMaxAge, urlUtils}) {
|
||||||
/** @private */
|
/** @private */
|
||||||
this.config = config;
|
this.permanentMaxAge = permanentMaxAge;
|
||||||
/** @private */
|
/** @private */
|
||||||
this.urlUtils = urlUtils;
|
this.urlUtils = urlUtils;
|
||||||
/** @private */
|
/** @private */
|
||||||
|
@ -55,7 +56,7 @@ class DynamicRedirectManager {
|
||||||
const {fromRegex, to, options: {permanent}} = this.redirects[redirectId];
|
const {fromRegex, to, options: {permanent}} = this.redirects[redirectId];
|
||||||
|
|
||||||
this.router.get(fromRegex, (req, res) => {
|
this.router.get(fromRegex, (req, res) => {
|
||||||
const maxAge = permanent ? this.config.permanentMaxAge : 0;
|
const maxAge = permanent ? this.permanentMaxAge : 0;
|
||||||
const toURL = parseURL(to);
|
const toURL = parseURL(to);
|
||||||
const toURLParams = parseQuerystring(toURL.query);
|
const toURLParams = parseQuerystring(toURL.query);
|
||||||
const currentURL = parseURL(req.url);
|
const currentURL = parseURL(req.url);
|
||||||
|
|
|
@ -12,8 +12,8 @@ const urlUtils = {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('DynamicRedirectManager', function () {
|
describe('DynamicRedirectManager', function () {
|
||||||
it('Prioritises the query params of the redirect', function () {
|
it('Prioritizes the query params of the redirect', function () {
|
||||||
const manager = new DynamicRedirectManager({permanentMaxAge: 100}, urlUtils);
|
const manager = new DynamicRedirectManager({permanentMaxAge: 100, urlUtils});
|
||||||
|
|
||||||
manager.addRedirect('/test-params', '/result?q=abc', {permanent: true});
|
manager.addRedirect('/test-params', '/result?q=abc', {permanent: true});
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ describe('DynamicRedirectManager', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Allows redirects to be removed', function () {
|
it('Allows redirects to be removed', function () {
|
||||||
const manager = new DynamicRedirectManager({permanentMaxAge: 100}, urlUtils);
|
const manager = new DynamicRedirectManager({permanentMaxAge: 100, urlUtils});
|
||||||
|
|
||||||
const id = manager.addRedirect('/test-params', '/result?q=abc', {permanent: true});
|
const id = manager.addRedirect('/test-params', '/result?q=abc', {permanent: true});
|
||||||
manager.removeRedirect(id);
|
manager.removeRedirect(id);
|
||||||
|
|
Loading…
Add table
Reference in a new issue