@sitecore-jss/sitecore-jss-nextjs 22.2.0-canary.63 → 22.2.0-canary.67
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.
|
@@ -65,6 +65,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
65
65
|
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
|
66
66
|
existsRedirect.target.includes(hostname))) {
|
|
67
67
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
68
|
+
req.nextUrl.locale = site.language;
|
|
68
69
|
}
|
|
69
70
|
const url = this.normalizeUrl(req.nextUrl.clone());
|
|
70
71
|
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
@@ -93,18 +94,20 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
93
94
|
}
|
|
94
95
|
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
95
96
|
url.href = prepareNewURL.href;
|
|
97
|
+
url.pathname = prepareNewURL.pathname;
|
|
98
|
+
url.search = prepareNewURL.search;
|
|
99
|
+
url.locale = req.nextUrl.locale;
|
|
96
100
|
}
|
|
97
|
-
const redirectUrl = decodeURIComponent(url.href);
|
|
98
101
|
/** return Response redirect with http code of redirect type **/
|
|
99
102
|
switch (existsRedirect.redirectType) {
|
|
100
103
|
case site_1.REDIRECT_TYPE_301: {
|
|
101
|
-
return this.createRedirectResponse(
|
|
104
|
+
return this.createRedirectResponse(url, res, 301, 'Moved Permanently');
|
|
102
105
|
}
|
|
103
106
|
case site_1.REDIRECT_TYPE_302: {
|
|
104
|
-
return this.createRedirectResponse(
|
|
107
|
+
return this.createRedirectResponse(url, res, 302, 'Found');
|
|
105
108
|
}
|
|
106
109
|
case site_1.REDIRECT_TYPE_SERVER_TRANSFER: {
|
|
107
|
-
return this.rewrite(
|
|
110
|
+
return this.rewrite(url.href, req, res || server_1.NextResponse.next());
|
|
108
111
|
}
|
|
109
112
|
default:
|
|
110
113
|
return res || server_1.NextResponse.next();
|
|
@@ -150,9 +153,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
150
153
|
getExistsRedirect(req, siteName) {
|
|
151
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
155
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
153
|
-
const
|
|
154
|
-
const tragetURL = normalizedUrl.pathname;
|
|
155
|
-
const targetQS = normalizedUrl.search || '';
|
|
156
|
+
const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
|
|
156
157
|
const language = this.getLanguage(req);
|
|
157
158
|
const modifyRedirects = structuredClone(redirects);
|
|
158
159
|
return modifyRedirects.length
|
|
@@ -192,20 +193,18 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
192
193
|
* string contributed to a successful redirect match.
|
|
193
194
|
*/
|
|
194
195
|
const matchedQueryString = this.isPermutedQueryMatch({
|
|
195
|
-
pathname:
|
|
196
|
+
pathname: targetURL,
|
|
196
197
|
queryString: targetQS,
|
|
197
198
|
pattern: redirect.pattern,
|
|
198
|
-
locale
|
|
199
|
+
locale,
|
|
199
200
|
});
|
|
200
201
|
// Save the matched query string (if found) into the redirect object
|
|
201
202
|
redirect.matchedQueryString = matchedQueryString || '';
|
|
202
203
|
// Return the redirect if the URL path or any query string permutation matches the pattern
|
|
203
|
-
return (((0, regex_parser_1.default)(redirect.pattern).test(
|
|
204
|
-
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${
|
|
204
|
+
return (((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
|
|
205
|
+
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
205
206
|
matchedQueryString) &&
|
|
206
|
-
(redirect.locale
|
|
207
|
-
? redirect.locale.toLowerCase() === req.nextUrl.locale.toLowerCase()
|
|
208
|
-
: true));
|
|
207
|
+
(redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
209
208
|
})
|
|
210
209
|
: undefined;
|
|
211
210
|
});
|
|
@@ -214,7 +213,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
214
213
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
215
214
|
* Next.js adds special parameters in the route called path.
|
|
216
215
|
* This method removes these special parameters.
|
|
217
|
-
* @param {
|
|
216
|
+
* @param {NextURL} url
|
|
218
217
|
* @returns {string} normalize url
|
|
219
218
|
*/
|
|
220
219
|
normalizeUrl(url) {
|
|
@@ -244,14 +243,15 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
244
243
|
return false;
|
|
245
244
|
})
|
|
246
245
|
.join('&');
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
|
|
247
|
+
url.search = newUrl.search;
|
|
248
|
+
url.pathname = newUrl.pathname;
|
|
249
|
+
url.href = newUrl.href;
|
|
250
|
+
return url;
|
|
251
251
|
}
|
|
252
252
|
/**
|
|
253
253
|
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
254
|
-
* @param {
|
|
254
|
+
* @param {NextURL} url The URL to redirect to.
|
|
255
255
|
* @param {Response} res The response object.
|
|
256
256
|
* @param {number} status The HTTP status code of the redirect.
|
|
257
257
|
* @param {string} statusText The status text of the redirect.
|
|
@@ -59,6 +59,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
59
59
|
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
|
60
60
|
existsRedirect.target.includes(hostname))) {
|
|
61
61
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
62
|
+
req.nextUrl.locale = site.language;
|
|
62
63
|
}
|
|
63
64
|
const url = this.normalizeUrl(req.nextUrl.clone());
|
|
64
65
|
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
@@ -87,18 +88,20 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
87
88
|
}
|
|
88
89
|
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
89
90
|
url.href = prepareNewURL.href;
|
|
91
|
+
url.pathname = prepareNewURL.pathname;
|
|
92
|
+
url.search = prepareNewURL.search;
|
|
93
|
+
url.locale = req.nextUrl.locale;
|
|
90
94
|
}
|
|
91
|
-
const redirectUrl = decodeURIComponent(url.href);
|
|
92
95
|
/** return Response redirect with http code of redirect type **/
|
|
93
96
|
switch (existsRedirect.redirectType) {
|
|
94
97
|
case REDIRECT_TYPE_301: {
|
|
95
|
-
return this.createRedirectResponse(
|
|
98
|
+
return this.createRedirectResponse(url, res, 301, 'Moved Permanently');
|
|
96
99
|
}
|
|
97
100
|
case REDIRECT_TYPE_302: {
|
|
98
|
-
return this.createRedirectResponse(
|
|
101
|
+
return this.createRedirectResponse(url, res, 302, 'Found');
|
|
99
102
|
}
|
|
100
103
|
case REDIRECT_TYPE_SERVER_TRANSFER: {
|
|
101
|
-
return this.rewrite(
|
|
104
|
+
return this.rewrite(url.href, req, res || NextResponse.next());
|
|
102
105
|
}
|
|
103
106
|
default:
|
|
104
107
|
return res || NextResponse.next();
|
|
@@ -144,9 +147,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
144
147
|
getExistsRedirect(req, siteName) {
|
|
145
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
149
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
147
|
-
const
|
|
148
|
-
const tragetURL = normalizedUrl.pathname;
|
|
149
|
-
const targetQS = normalizedUrl.search || '';
|
|
150
|
+
const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
|
|
150
151
|
const language = this.getLanguage(req);
|
|
151
152
|
const modifyRedirects = structuredClone(redirects);
|
|
152
153
|
return modifyRedirects.length
|
|
@@ -186,20 +187,18 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
186
187
|
* string contributed to a successful redirect match.
|
|
187
188
|
*/
|
|
188
189
|
const matchedQueryString = this.isPermutedQueryMatch({
|
|
189
|
-
pathname:
|
|
190
|
+
pathname: targetURL,
|
|
190
191
|
queryString: targetQS,
|
|
191
192
|
pattern: redirect.pattern,
|
|
192
|
-
locale
|
|
193
|
+
locale,
|
|
193
194
|
});
|
|
194
195
|
// Save the matched query string (if found) into the redirect object
|
|
195
196
|
redirect.matchedQueryString = matchedQueryString || '';
|
|
196
197
|
// Return the redirect if the URL path or any query string permutation matches the pattern
|
|
197
|
-
return ((regexParser(redirect.pattern).test(
|
|
198
|
-
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${
|
|
198
|
+
return ((regexParser(redirect.pattern).test(targetURL) ||
|
|
199
|
+
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
199
200
|
matchedQueryString) &&
|
|
200
|
-
(redirect.locale
|
|
201
|
-
? redirect.locale.toLowerCase() === req.nextUrl.locale.toLowerCase()
|
|
202
|
-
: true));
|
|
201
|
+
(redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
203
202
|
})
|
|
204
203
|
: undefined;
|
|
205
204
|
});
|
|
@@ -208,7 +207,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
208
207
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
209
208
|
* Next.js adds special parameters in the route called path.
|
|
210
209
|
* This method removes these special parameters.
|
|
211
|
-
* @param {
|
|
210
|
+
* @param {NextURL} url
|
|
212
211
|
* @returns {string} normalize url
|
|
213
212
|
*/
|
|
214
213
|
normalizeUrl(url) {
|
|
@@ -238,14 +237,15 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
238
237
|
return false;
|
|
239
238
|
})
|
|
240
239
|
.join('&');
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
|
|
241
|
+
url.search = newUrl.search;
|
|
242
|
+
url.pathname = newUrl.pathname;
|
|
243
|
+
url.href = newUrl.href;
|
|
244
|
+
return url;
|
|
245
245
|
}
|
|
246
246
|
/**
|
|
247
247
|
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
248
|
-
* @param {
|
|
248
|
+
* @param {NextURL} url The URL to redirect to.
|
|
249
249
|
* @param {Response} res The response object.
|
|
250
250
|
* @param {number} status The HTTP status code of the redirect.
|
|
251
251
|
* @param {string} statusText The status text of the redirect.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.2.0-canary.
|
|
3
|
+
"version": "22.2.0-canary.67",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"react-dom": "^18.2.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@sitecore-jss/sitecore-jss": "^22.2.0-canary.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^22.2.0-canary.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^22.2.0-canary.
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "^22.2.0-canary.67",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.2.0-canary.67",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "^22.2.0-canary.67",
|
|
78
78
|
"@vercel/kv": "^0.2.1",
|
|
79
79
|
"prop-types": "^15.8.1",
|
|
80
80
|
"regex-parser": "^2.2.11",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"description": "",
|
|
84
84
|
"types": "types/index.d.ts",
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "8773ee414183e87677989c98398ebf4199e493cc",
|
|
86
86
|
"files": [
|
|
87
87
|
"dist",
|
|
88
88
|
"types",
|
|
@@ -41,13 +41,13 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
|
41
41
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
42
42
|
* Next.js adds special parameters in the route called path.
|
|
43
43
|
* This method removes these special parameters.
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {NextURL} url
|
|
45
45
|
* @returns {string} normalize url
|
|
46
46
|
*/
|
|
47
47
|
private normalizeUrl;
|
|
48
48
|
/**
|
|
49
49
|
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
50
|
-
* @param {
|
|
50
|
+
* @param {NextURL} url The URL to redirect to.
|
|
51
51
|
* @param {Response} res The response object.
|
|
52
52
|
* @param {number} status The HTTP status code of the redirect.
|
|
53
53
|
* @param {string} statusText The status text of the redirect.
|