@sitecore-jss/sitecore-jss-nextjs 22.1.0-canary.80 → 22.1.0-canary.82
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.
|
@@ -12,4 +12,4 @@ exports.EDITING_PASS_THROUGH_HEADERS = ['authorization', 'cookie'];
|
|
|
12
12
|
/**
|
|
13
13
|
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
14
14
|
*/
|
|
15
|
-
exports.EDITING_ALLOWED_ORIGINS = ['https://pages
|
|
15
|
+
exports.EDITING_ALLOWED_ORIGINS = ['https://pages.sitecorecloud.io'];
|
|
@@ -43,6 +43,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
43
43
|
hostname,
|
|
44
44
|
});
|
|
45
45
|
const createResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
var _a;
|
|
46
47
|
if (this.config.disabled && this.config.disabled(req, res || server_1.NextResponse.next())) {
|
|
47
48
|
sitecore_jss_1.debug.redirects('skipped (redirects middleware is disabled)');
|
|
48
49
|
return res || server_1.NextResponse.next();
|
|
@@ -64,27 +65,33 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
64
65
|
existsRedirect.target.includes(hostname))) {
|
|
65
66
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
66
67
|
}
|
|
67
|
-
const url = req.nextUrl.clone();
|
|
68
|
+
const url = this.normalizeUrl(req.nextUrl.clone());
|
|
68
69
|
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
69
70
|
url.href = existsRedirect.target;
|
|
70
71
|
}
|
|
71
72
|
else {
|
|
72
|
-
const source =
|
|
73
|
+
const source = `${url.pathname.replace(/\/*$/gi, '')}${url.search}`;
|
|
73
74
|
const urlFirstPart = existsRedirect.target.split('/')[1];
|
|
74
75
|
if (this.locales.includes(urlFirstPart)) {
|
|
75
|
-
|
|
76
|
+
req.nextUrl.locale = urlFirstPart;
|
|
76
77
|
existsRedirect.target = existsRedirect.target.replace(`/${urlFirstPart}`, '');
|
|
77
78
|
}
|
|
78
79
|
const target = source
|
|
79
80
|
.replace((0, regex_parser_1.default)(existsRedirect.pattern), existsRedirect.target)
|
|
80
81
|
.replace(/^\/\//, '/')
|
|
81
82
|
.split('?');
|
|
82
|
-
url.
|
|
83
|
-
|
|
84
|
-
url.search =
|
|
83
|
+
if (url.search && existsRedirect.isQueryStringPreserved) {
|
|
84
|
+
const targetQueryString = (_a = target[1]) !== null && _a !== void 0 ? _a : '';
|
|
85
|
+
url.search = '?' + new URLSearchParams(`${url.search}&${targetQueryString}`).toString();
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
else if (target[1]) {
|
|
88
|
+
url.search = '?' + target[1];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
url.search = '';
|
|
92
|
+
}
|
|
93
|
+
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
94
|
+
url.href = prepareNewURL.href;
|
|
88
95
|
}
|
|
89
96
|
const redirectUrl = decodeURIComponent(url.href);
|
|
90
97
|
/** return Response redirect with http code of redirect type **/
|
|
@@ -140,7 +147,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
140
147
|
getExistsRedirect(req, siteName) {
|
|
141
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
149
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
143
|
-
const normalizedUrl =
|
|
150
|
+
const normalizedUrl = this.normalizeUrl(req.nextUrl.clone());
|
|
144
151
|
const tragetURL = normalizedUrl.pathname;
|
|
145
152
|
const targetQS = normalizedUrl.search || '';
|
|
146
153
|
const language = this.getLanguage(req);
|
|
@@ -155,7 +162,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
155
162
|
.replace(/(?<!\\)\?/g, '\\?')
|
|
156
163
|
.replace(/\$\/gi$/g, '')}[\/]?$/gi`;
|
|
157
164
|
return (((0, regex_parser_1.default)(redirect.pattern).test(tragetURL) ||
|
|
158
|
-
(0, regex_parser_1.default)(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
|
|
165
|
+
(0, regex_parser_1.default)(redirect.pattern).test(`${tragetURL.replace(/\/*$/gi, '')}${targetQS}`) ||
|
|
159
166
|
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
|
|
160
167
|
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}${targetQS}`)) &&
|
|
161
168
|
(redirect.locale
|
|
@@ -169,18 +176,17 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
169
176
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
170
177
|
* Next.js adds special parameters in the route called path.
|
|
171
178
|
* This method removes these special parameters.
|
|
172
|
-
* @param {
|
|
173
|
-
* @
|
|
174
|
-
* @returns {string} modified url
|
|
179
|
+
* @param {URL} url
|
|
180
|
+
* @returns {string} normalize url
|
|
175
181
|
*/
|
|
176
|
-
normalizeUrl(
|
|
177
|
-
if (!
|
|
178
|
-
return
|
|
182
|
+
normalizeUrl(url) {
|
|
183
|
+
if (!url.search) {
|
|
184
|
+
return url;
|
|
179
185
|
}
|
|
180
186
|
/**
|
|
181
187
|
* Prepare special parameters for exclusion.
|
|
182
188
|
*/
|
|
183
|
-
const splittedPathname = pathname
|
|
189
|
+
const splittedPathname = url.pathname
|
|
184
190
|
.split('/')
|
|
185
191
|
.filter((route) => route)
|
|
186
192
|
.map((route) => `path=${route}`);
|
|
@@ -190,7 +196,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
190
196
|
* When a user clicks on this link, Next.js should generate a link for the middleware, formatted like this:
|
|
191
197
|
* http://host/about/contact/us?path=about&path=contact&path=us
|
|
192
198
|
*/
|
|
193
|
-
const newQueryString =
|
|
199
|
+
const newQueryString = url.search
|
|
194
200
|
.replace(/^\?/, '')
|
|
195
201
|
.split('&')
|
|
196
202
|
.filter((param) => {
|
|
@@ -201,9 +207,9 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
201
207
|
})
|
|
202
208
|
.join('&');
|
|
203
209
|
if (newQueryString) {
|
|
204
|
-
return `${pathname}?${newQueryString}
|
|
210
|
+
return new URL(`${url.pathname}?${newQueryString}`, url.origin);
|
|
205
211
|
}
|
|
206
|
-
return pathname;
|
|
212
|
+
return new URL(`${url.pathname}`, url.origin);
|
|
207
213
|
}
|
|
208
214
|
}
|
|
209
215
|
exports.RedirectsMiddleware = RedirectsMiddleware;
|
|
@@ -9,4 +9,4 @@ export const EDITING_PASS_THROUGH_HEADERS = ['authorization', 'cookie'];
|
|
|
9
9
|
/**
|
|
10
10
|
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
11
11
|
*/
|
|
12
|
-
export const EDITING_ALLOWED_ORIGINS = ['https://pages
|
|
12
|
+
export const EDITING_ALLOWED_ORIGINS = ['https://pages.sitecorecloud.io'];
|
|
@@ -37,6 +37,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
37
37
|
hostname,
|
|
38
38
|
});
|
|
39
39
|
const createResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a;
|
|
40
41
|
if (this.config.disabled && this.config.disabled(req, res || NextResponse.next())) {
|
|
41
42
|
debug.redirects('skipped (redirects middleware is disabled)');
|
|
42
43
|
return res || NextResponse.next();
|
|
@@ -58,27 +59,33 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
58
59
|
existsRedirect.target.includes(hostname))) {
|
|
59
60
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
60
61
|
}
|
|
61
|
-
const url = req.nextUrl.clone();
|
|
62
|
+
const url = this.normalizeUrl(req.nextUrl.clone());
|
|
62
63
|
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
63
64
|
url.href = existsRedirect.target;
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
|
-
const source =
|
|
67
|
+
const source = `${url.pathname.replace(/\/*$/gi, '')}${url.search}`;
|
|
67
68
|
const urlFirstPart = existsRedirect.target.split('/')[1];
|
|
68
69
|
if (this.locales.includes(urlFirstPart)) {
|
|
69
|
-
|
|
70
|
+
req.nextUrl.locale = urlFirstPart;
|
|
70
71
|
existsRedirect.target = existsRedirect.target.replace(`/${urlFirstPart}`, '');
|
|
71
72
|
}
|
|
72
73
|
const target = source
|
|
73
74
|
.replace(regexParser(existsRedirect.pattern), existsRedirect.target)
|
|
74
75
|
.replace(/^\/\//, '/')
|
|
75
76
|
.split('?');
|
|
76
|
-
url.
|
|
77
|
-
|
|
78
|
-
url.search =
|
|
77
|
+
if (url.search && existsRedirect.isQueryStringPreserved) {
|
|
78
|
+
const targetQueryString = (_a = target[1]) !== null && _a !== void 0 ? _a : '';
|
|
79
|
+
url.search = '?' + new URLSearchParams(`${url.search}&${targetQueryString}`).toString();
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
else if (target[1]) {
|
|
82
|
+
url.search = '?' + target[1];
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
url.search = '';
|
|
86
|
+
}
|
|
87
|
+
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
88
|
+
url.href = prepareNewURL.href;
|
|
82
89
|
}
|
|
83
90
|
const redirectUrl = decodeURIComponent(url.href);
|
|
84
91
|
/** return Response redirect with http code of redirect type **/
|
|
@@ -134,7 +141,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
134
141
|
getExistsRedirect(req, siteName) {
|
|
135
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
143
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
137
|
-
const normalizedUrl =
|
|
144
|
+
const normalizedUrl = this.normalizeUrl(req.nextUrl.clone());
|
|
138
145
|
const tragetURL = normalizedUrl.pathname;
|
|
139
146
|
const targetQS = normalizedUrl.search || '';
|
|
140
147
|
const language = this.getLanguage(req);
|
|
@@ -149,7 +156,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
149
156
|
.replace(/(?<!\\)\?/g, '\\?')
|
|
150
157
|
.replace(/\$\/gi$/g, '')}[\/]?$/gi`;
|
|
151
158
|
return ((regexParser(redirect.pattern).test(tragetURL) ||
|
|
152
|
-
regexParser(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
|
|
159
|
+
regexParser(redirect.pattern).test(`${tragetURL.replace(/\/*$/gi, '')}${targetQS}`) ||
|
|
153
160
|
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
|
|
154
161
|
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}${targetQS}`)) &&
|
|
155
162
|
(redirect.locale
|
|
@@ -163,18 +170,17 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
163
170
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
164
171
|
* Next.js adds special parameters in the route called path.
|
|
165
172
|
* This method removes these special parameters.
|
|
166
|
-
* @param {
|
|
167
|
-
* @
|
|
168
|
-
* @returns {string} modified url
|
|
173
|
+
* @param {URL} url
|
|
174
|
+
* @returns {string} normalize url
|
|
169
175
|
*/
|
|
170
|
-
normalizeUrl(
|
|
171
|
-
if (!
|
|
172
|
-
return
|
|
176
|
+
normalizeUrl(url) {
|
|
177
|
+
if (!url.search) {
|
|
178
|
+
return url;
|
|
173
179
|
}
|
|
174
180
|
/**
|
|
175
181
|
* Prepare special parameters for exclusion.
|
|
176
182
|
*/
|
|
177
|
-
const splittedPathname = pathname
|
|
183
|
+
const splittedPathname = url.pathname
|
|
178
184
|
.split('/')
|
|
179
185
|
.filter((route) => route)
|
|
180
186
|
.map((route) => `path=${route}`);
|
|
@@ -184,7 +190,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
184
190
|
* When a user clicks on this link, Next.js should generate a link for the middleware, formatted like this:
|
|
185
191
|
* http://host/about/contact/us?path=about&path=contact&path=us
|
|
186
192
|
*/
|
|
187
|
-
const newQueryString =
|
|
193
|
+
const newQueryString = url.search
|
|
188
194
|
.replace(/^\?/, '')
|
|
189
195
|
.split('&')
|
|
190
196
|
.filter((param) => {
|
|
@@ -195,8 +201,8 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
195
201
|
})
|
|
196
202
|
.join('&');
|
|
197
203
|
if (newQueryString) {
|
|
198
|
-
return `${pathname}?${newQueryString}
|
|
204
|
+
return new URL(`${url.pathname}?${newQueryString}`, url.origin);
|
|
199
205
|
}
|
|
200
|
-
return pathname;
|
|
206
|
+
return new URL(`${url.pathname}`, url.origin);
|
|
201
207
|
}
|
|
202
208
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.1.0-canary.
|
|
3
|
+
"version": "22.1.0-canary.82",
|
|
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.1.0-canary.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^22.1.0-canary.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^22.1.0-canary.
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "^22.1.0-canary.82",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.1.0-canary.82",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "^22.1.0-canary.82",
|
|
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": "cfbb0bf66f12d1fd63d9806f54404cbc3bcee52b",
|
|
86
86
|
"files": [
|
|
87
87
|
"dist",
|
|
88
88
|
"types",
|
|
@@ -41,9 +41,8 @@ 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 {
|
|
45
|
-
* @
|
|
46
|
-
* @returns {string} modified url
|
|
44
|
+
* @param {URL} url
|
|
45
|
+
* @returns {string} normalize url
|
|
47
46
|
*/
|
|
48
47
|
private normalizeUrl;
|
|
49
48
|
}
|