@sitecore-jss/sitecore-jss-nextjs 22.6.0-canary.19 → 22.6.0-canary.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -62,23 +62,29 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
62
62
|
*/
|
|
63
63
|
getExistsRedirect(req, siteName) {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const { pathname:
|
|
65
|
+
const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
|
|
66
66
|
const locale = this.getLanguage(req);
|
|
67
|
-
const normalizedPath =
|
|
67
|
+
const normalizedPath = incomingURL.replace(/\/*$/gi, '');
|
|
68
68
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
69
69
|
const language = this.getLanguage(req);
|
|
70
70
|
const modifyRedirects = structuredClone(redirects);
|
|
71
71
|
let matchedQueryString;
|
|
72
|
+
const localePath = `/${locale}${normalizedPath}`.toLowerCase();
|
|
72
73
|
return modifyRedirects.length
|
|
73
74
|
? modifyRedirects.find((redirect) => {
|
|
75
|
+
// process static URL (non-regex) rules
|
|
74
76
|
if ((0, utils_1.isRegexOrUrl)(redirect.pattern) === 'url') {
|
|
75
77
|
const [patternPath, patternQS] = redirect.pattern.endsWith('/')
|
|
76
|
-
? redirect.pattern
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
? redirect.pattern
|
|
79
|
+
.toLowerCase()
|
|
80
|
+
.slice(0, -1)
|
|
81
|
+
.split('?')
|
|
82
|
+
: redirect.pattern.toLowerCase().split('?');
|
|
83
|
+
return ((patternPath === localePath || patternPath === normalizedPath) &&
|
|
79
84
|
(!patternQS ||
|
|
80
|
-
(0, utils_1.areURLSearchParamsEqual)(new URLSearchParams(patternQS), new URLSearchParams(
|
|
85
|
+
(0, utils_1.areURLSearchParamsEqual)(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
|
|
81
86
|
}
|
|
87
|
+
// process regex rules
|
|
82
88
|
// Modify the redirect pattern to ignore the language prefix in the path
|
|
83
89
|
// And escapes non-special "?" characters in a string or regex.
|
|
84
90
|
redirect.pattern = (0, utils_1.escapeNonSpecialQuestionMarks)(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
|
|
@@ -90,21 +96,15 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
90
96
|
.replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
|
|
91
97
|
// Redirect pattern matches the full incoming URL with query string present
|
|
92
98
|
matchedQueryString = [
|
|
93
|
-
(0, regex_parser_1.default)(redirect.pattern).test(`${
|
|
94
|
-
(0, regex_parser_1.default)(redirect.pattern).test(
|
|
99
|
+
(0, regex_parser_1.default)(redirect.pattern).test(`${localePath}${incomingQS}`),
|
|
100
|
+
(0, regex_parser_1.default)(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
|
|
95
101
|
].some(Boolean)
|
|
96
|
-
?
|
|
102
|
+
? incomingQS
|
|
97
103
|
: undefined;
|
|
98
104
|
// Save the matched query string (if found) into the redirect object
|
|
99
105
|
redirect.matchedQueryString = matchedQueryString || '';
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
patern: redirect.pattern,
|
|
103
|
-
targetURL,
|
|
104
|
-
targetQS,
|
|
105
|
-
});
|
|
106
|
-
return (!!((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
|
|
107
|
-
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
106
|
+
return (!!((0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
|
|
107
|
+
(0, regex_parser_1.default)(redirect.pattern).test(incomingURL) ||
|
|
108
108
|
matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
109
109
|
})
|
|
110
110
|
: undefined;
|
|
@@ -148,11 +148,11 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
148
148
|
site = this.getSite(req, res);
|
|
149
149
|
// Find the redirect from result of RedirectService
|
|
150
150
|
const existsRedirect = yield this.getExistsRedirect(req, site.name);
|
|
151
|
-
sitecore_jss_1.debug.redirects('Existing redirect: %o', { existsRedirect });
|
|
152
151
|
if (!existsRedirect) {
|
|
153
152
|
sitecore_jss_1.debug.redirects('skipped (redirect does not exist)');
|
|
154
153
|
return response;
|
|
155
154
|
}
|
|
155
|
+
sitecore_jss_1.debug.redirects('Matched redirect rule: %o', { existsRedirect });
|
|
156
156
|
// Find context site language and replace token
|
|
157
157
|
if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
|
|
158
158
|
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
|
@@ -56,23 +56,29 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
56
56
|
*/
|
|
57
57
|
getExistsRedirect(req, siteName) {
|
|
58
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const { pathname:
|
|
59
|
+
const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
|
|
60
60
|
const locale = this.getLanguage(req);
|
|
61
|
-
const normalizedPath =
|
|
61
|
+
const normalizedPath = incomingURL.replace(/\/*$/gi, '');
|
|
62
62
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
63
63
|
const language = this.getLanguage(req);
|
|
64
64
|
const modifyRedirects = structuredClone(redirects);
|
|
65
65
|
let matchedQueryString;
|
|
66
|
+
const localePath = `/${locale}${normalizedPath}`.toLowerCase();
|
|
66
67
|
return modifyRedirects.length
|
|
67
68
|
? modifyRedirects.find((redirect) => {
|
|
69
|
+
// process static URL (non-regex) rules
|
|
68
70
|
if (isRegexOrUrl(redirect.pattern) === 'url') {
|
|
69
71
|
const [patternPath, patternQS] = redirect.pattern.endsWith('/')
|
|
70
|
-
? redirect.pattern
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
? redirect.pattern
|
|
73
|
+
.toLowerCase()
|
|
74
|
+
.slice(0, -1)
|
|
75
|
+
.split('?')
|
|
76
|
+
: redirect.pattern.toLowerCase().split('?');
|
|
77
|
+
return ((patternPath === localePath || patternPath === normalizedPath) &&
|
|
73
78
|
(!patternQS ||
|
|
74
|
-
areURLSearchParamsEqual(new URLSearchParams(patternQS), new URLSearchParams(
|
|
79
|
+
areURLSearchParamsEqual(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
|
|
75
80
|
}
|
|
81
|
+
// process regex rules
|
|
76
82
|
// Modify the redirect pattern to ignore the language prefix in the path
|
|
77
83
|
// And escapes non-special "?" characters in a string or regex.
|
|
78
84
|
redirect.pattern = escapeNonSpecialQuestionMarks(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
|
|
@@ -84,21 +90,15 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
84
90
|
.replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
|
|
85
91
|
// Redirect pattern matches the full incoming URL with query string present
|
|
86
92
|
matchedQueryString = [
|
|
87
|
-
regexParser(redirect.pattern).test(`${
|
|
88
|
-
regexParser(redirect.pattern).test(
|
|
93
|
+
regexParser(redirect.pattern).test(`${localePath}${incomingQS}`),
|
|
94
|
+
regexParser(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
|
|
89
95
|
].some(Boolean)
|
|
90
|
-
?
|
|
96
|
+
? incomingQS
|
|
91
97
|
: undefined;
|
|
92
98
|
// Save the matched query string (if found) into the redirect object
|
|
93
99
|
redirect.matchedQueryString = matchedQueryString || '';
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
patern: redirect.pattern,
|
|
97
|
-
targetURL,
|
|
98
|
-
targetQS,
|
|
99
|
-
});
|
|
100
|
-
return (!!(regexParser(redirect.pattern).test(targetURL) ||
|
|
101
|
-
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
100
|
+
return (!!(regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
|
|
101
|
+
regexParser(redirect.pattern).test(incomingURL) ||
|
|
102
102
|
matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
103
103
|
})
|
|
104
104
|
: undefined;
|
|
@@ -142,11 +142,11 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
142
142
|
site = this.getSite(req, res);
|
|
143
143
|
// Find the redirect from result of RedirectService
|
|
144
144
|
const existsRedirect = yield this.getExistsRedirect(req, site.name);
|
|
145
|
-
debug.redirects('Existing redirect: %o', { existsRedirect });
|
|
146
145
|
if (!existsRedirect) {
|
|
147
146
|
debug.redirects('skipped (redirect does not exist)');
|
|
148
147
|
return response;
|
|
149
148
|
}
|
|
149
|
+
debug.redirects('Matched redirect rule: %o', { existsRedirect });
|
|
150
150
|
// Find context site language and replace token
|
|
151
151
|
if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
|
|
152
152
|
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.6.0-canary.
|
|
3
|
+
"version": "22.6.0-canary.20",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"react-dom": "^18.2.0"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@sitecore-jss/sitecore-jss": "22.6.0-canary.
|
|
78
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "22.6.0-canary.
|
|
79
|
-
"@sitecore-jss/sitecore-jss-react": "22.6.0-canary.
|
|
77
|
+
"@sitecore-jss/sitecore-jss": "22.6.0-canary.20",
|
|
78
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "22.6.0-canary.20",
|
|
79
|
+
"@sitecore-jss/sitecore-jss-react": "22.6.0-canary.20",
|
|
80
80
|
"@vercel/kv": "^0.2.1",
|
|
81
81
|
"prop-types": "^15.8.1",
|
|
82
82
|
"regex-parser": "^2.2.11",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
},
|
|
85
85
|
"description": "",
|
|
86
86
|
"types": "types/index.d.ts",
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "4e59803c65beb6bab91cc63da0f87635ecc908a7",
|
|
88
88
|
"files": [
|
|
89
89
|
"dist",
|
|
90
90
|
"types",
|