Skip to content

Commit

Permalink
[sitecore-jss-nextjs]: fixed redirects middleware when pattern use d…
Browse files Browse the repository at this point in the history
…efault locale in regexp (#1696)

* [sitecore-jss-nextjs]: fixed redirects middleware when pattern use default local in regexp

* [sitecore-jss-nextjs]: changed CHANGELOG

* [sitecore-jss-nextjs]: fixed ESlint errors

* [sitecore-jss-nextjs]: refactoring condition of redirects

---------

Co-authored-by: Ruslan Matkovskyi <[email protected]>
  • Loading branch information
sc-ruslanmatkovskyi and Ruslan Matkovskyi authored Dec 15, 2023
1 parent be27caf commit 2b25de6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Our versioning strategy is as follows:
* `[templates/node-headless-ssr-proxy]` `[node-headless-ssr-proxy]` Add sc_site qs parameter to Layout Service requests by default ([#1660](https://github.com/Sitecore/jss/pull/1660))
* `[templates/nextjs-sxa]` Fixed Image component when there is using Banner variant which set property background-image when image is empty. ([#1689](https://github.com/Sitecore/jss/pull/1689)) ([#1692](https://github.com/Sitecore/jss/pull/1692))
* `[sitecore-jss-react]` `[templates/nextjs-xmcloud]` Ensure FEAAS and BYOC components can correctly use item datasources ([#1694](https://github.com/Sitecore/jss/pull/1694))
* `[sitecore-jss-nextjs]` Fix loop error in redirect middleware when the pattern of redirect has default locale. ([#1696](https://github.com/Sitecore/jss/pull/1696))

### 🛠 Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ export class RedirectsMiddleware extends MiddlewareBase {
const redirects = await this.redirectsService.fetchRedirects(siteName);
const tragetURL = req.nextUrl.pathname;
const targetQS = req.nextUrl.search || '';
const language = this.getLanguage(req);
const modifyRedirects = structuredClone(redirects);

return redirects.length
? redirects.find((redirect: RedirectInfo) => {
return modifyRedirects.length
? modifyRedirects.find((redirect: RedirectInfo) => {
redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
redirect.pattern = `/^\/${redirect.pattern
.replace(/^\/|\/$/g, '')
.replace(/^\^\/|\/\$$/g, '')
Expand Down

0 comments on commit 2b25de6

Please sign in to comment.