Skip to content

Commit

Permalink
Merge pull request #28 from apostrophecms/release-1.4.0
Browse files Browse the repository at this point in the history
Release 1.4.0
  • Loading branch information
boutell committed Feb 24, 2024
2 parents e58b5d9 + e04261e commit 6fb6b75
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 1.4.0 (2024-02-23)

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
* 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

Many thanks for this contribution.

## 1.3.0 (2023-11-03)

- Adds possibility to redirect from a locale to another one using internal redirects.
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 6fb6b75

Please sign in to comment.