From 8137cab9fa72fdde1043910af1ec54695bc217e4 Mon Sep 17 00:00:00 2001 From: Thomas Boutell Date: Fri, 23 Feb 2024 14:05:17 -0500 Subject: [PATCH 1/3] changelog --- CHANGELOG.md | 14 ++++++++++++++ README.md | 16 ++++++++++++++++ index.js | 6 +++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d081397..f56a024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## UNRELEASED + +Several fixes and improvements contributed by Stéphane Maccari of Michelin: + +* Add a way to modify the target url before doing the redirection +* Irrelevant SEO fields are properly removed from redirect pieces +* The `ignoreQueryString` field is honored properly +* Redirects to internal pages are saved properly +* `before` option added, giving the option of running the middleware earlier, e.g. before `@apostrophecms/global` +* Performance enhancement: skip the redirect check for API URLs like `/api/v1/...`. This can be +overridden using the `skip` option + +Many thanks for this contribution. + ## 1.3.0 (2023-11-03) - Adds possibility to redirect from a locale to another one using internal redirects. diff --git a/README.md b/README.md index 874dc1c..e72be4e 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,22 @@ By passing `withType` to your configuration you can specify the document type yo **Note:** Apostrophe 2 supported creating relationships to multiple doc types from a single interface. This feature is still being ported to Apostrophe 3, as such redirects can only specify a single doc type to redirect to. +### `skip` + +For performance the redirect check can be skipped for URLs matching certain regular expressions. +The default configuration of the `skip` option is: + +```javascript +// Other modules, then... +'@apostrophecms/redirect': { + options: { + skip: [ /\/api\/v1\/.*/ ] + } +} +``` + +If you wish to skip other patterns, we recommend keeping the default one as it speeds up API calls. + ## Usage While logged in as an admin, click the "Redirects" button. A list of redirects appears, initially empty. Add as many redirects as you like. The "from" URL must begin with a `/`. The "to" URL may be anything and need not be on your site. The "description" field is for your own convenience. diff --git a/index.js b/index.js index a123d5a..8665166 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ module.exports = { }, openGraph: false, // Disables @apostrophecms/open-graph for redirects seoFields: false, // Disables @apostrophecms/seo for redirects - regExpWhiteList: [ /\/api\/v1\/.*/ ], + skip: [ /\/api\/v1\/.*/ ], before: null }, init(self) { @@ -166,11 +166,11 @@ module.exports = { async middleware(req, res, next) { try { - if (self.options.regExpWhiteList.find((regExp) => regExp.test(req.originalUrl))) { + if (self.options.skip.find((regExp) => regExp.test(req.originalUrl))) { return next(); } } catch (e) { - self.apos.util.error('Error checking redirect white list: ', e); + self.apos.util.error('Error checking redirect allow list: ', e); } try { From f17b2f18733ff122f8a1a6e142bde3d30121fdb0 Mon Sep 17 00:00:00 2001 From: Thomas Boutell Date: Fri, 23 Feb 2024 14:05:57 -0500 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f56a024..20a92f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Several fixes and improvements contributed by Stéphane Maccari of Michelin: * Irrelevant SEO fields are properly removed from redirect pieces * The `ignoreQueryString` field is honored properly * Redirects to internal pages are saved properly +* Admins adding redirects may now elect to pass on the query string as part of the redirect * `before` option added, giving the option of running the middleware earlier, e.g. before `@apostrophecms/global` * Performance enhancement: skip the redirect check for API URLs like `/api/v1/...`. This can be overridden using the `skip` option From e04261ebed13c0760758e3dbd1e3c0da6a7c13da Mon Sep 17 00:00:00 2001 From: Thomas Boutell Date: Fri, 23 Feb 2024 14:06:13 -0500 Subject: [PATCH 3/3] release 1.4.0 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20a92f6..d5b8891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## UNRELEASED +## 1.4.0 (2024-02-23) Several fixes and improvements contributed by Stéphane Maccari of Michelin: diff --git a/package.json b/package.json index fda22fa..61bbf4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@apostrophecms/redirect", - "version": "1.3.0", + "version": "1.4.0", "description": "Manage redirects for Apostrophe 3", "main": "index.js", "scripts": {