@sitecore-content-sdk/nextjs 2.1.0-canary.7 → 2.1.0-canary.9
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,7 +65,7 @@ class RedirectsProxy extends proxy_1.ProxyBase {
|
|
|
65
65
|
}
|
|
66
66
|
site = this.getSite(req, res);
|
|
67
67
|
// Find the redirect from result of RedirectService
|
|
68
|
-
const existsRedirect = await this.getExistsRedirect(req, site.name);
|
|
68
|
+
const existsRedirect = await this.getExistsRedirect(req, site.name, language);
|
|
69
69
|
if (!existsRedirect) {
|
|
70
70
|
debug_1.default.redirects('skipped (redirect does not exist)');
|
|
71
71
|
return res;
|
|
@@ -202,15 +202,14 @@ class RedirectsProxy extends proxy_1.ProxyBase {
|
|
|
202
202
|
* @returns Promise<RedirectInfo | undefined>
|
|
203
203
|
* @private
|
|
204
204
|
*/
|
|
205
|
-
async getExistsRedirect(req, siteName) {
|
|
205
|
+
async getExistsRedirect(req, siteName, requestLocale) {
|
|
206
206
|
if (!this.redirectsService) {
|
|
207
207
|
return undefined;
|
|
208
208
|
}
|
|
209
209
|
const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
|
|
210
210
|
const normalizedPath = incomingURL.replace(/\/*$/gi, '').toLowerCase();
|
|
211
211
|
const redirects = await this.redirectsService.fetchRedirects(siteName);
|
|
212
|
-
// locale of current request (from URL, headers or otherwise), used to match versioned redirect rules
|
|
213
|
-
const requestLocale = this.getLanguage(req);
|
|
212
|
+
// using locale of current request (from URL, headers or otherwise), used to match versioned redirect rules
|
|
214
213
|
const matchedLocaleRedirect = this.matchRedirectItemRedirect(redirects, requestLocale, normalizedPath);
|
|
215
214
|
if (matchedLocaleRedirect) {
|
|
216
215
|
return matchedLocaleRedirect;
|
|
@@ -284,16 +283,17 @@ class RedirectsProxy extends proxy_1.ProxyBase {
|
|
|
284
283
|
* Processes redirect rules from redirect items (language-versioned)
|
|
285
284
|
* @param {RedirectResult[]} redirects redirect entries from Edge
|
|
286
285
|
* @param {string} locale current request locale
|
|
287
|
-
* @param {string} currentPath current request path
|
|
286
|
+
* @param {string} currentPath current request path
|
|
288
287
|
* @returns {RedirectResult | undefined} matched redirect item redirect result or undefined
|
|
289
288
|
* @private
|
|
290
289
|
*/
|
|
291
290
|
matchRedirectItemRedirect(redirects, locale, currentPath) {
|
|
291
|
+
const nonLocalePath = currentPath.replace(new RegExp(`^\/?${locale}\/`, 'i'), '/');
|
|
292
292
|
return redirects.length
|
|
293
293
|
? redirects.find((redirect) => {
|
|
294
294
|
const patternPath = redirect.pattern.replace(/\/*$/g, '').toLowerCase();
|
|
295
295
|
// locale rules are easy and nice
|
|
296
|
-
return redirect.locale === locale && patternPath ===
|
|
296
|
+
return redirect.locale === locale && patternPath === nonLocalePath;
|
|
297
297
|
})
|
|
298
298
|
: undefined;
|
|
299
299
|
}
|
|
@@ -59,7 +59,7 @@ export class RedirectsProxy extends ProxyBase {
|
|
|
59
59
|
}
|
|
60
60
|
site = this.getSite(req, res);
|
|
61
61
|
// Find the redirect from result of RedirectService
|
|
62
|
-
const existsRedirect = await this.getExistsRedirect(req, site.name);
|
|
62
|
+
const existsRedirect = await this.getExistsRedirect(req, site.name, language);
|
|
63
63
|
if (!existsRedirect) {
|
|
64
64
|
debug.redirects('skipped (redirect does not exist)');
|
|
65
65
|
return res;
|
|
@@ -196,15 +196,14 @@ export class RedirectsProxy extends ProxyBase {
|
|
|
196
196
|
* @returns Promise<RedirectInfo | undefined>
|
|
197
197
|
* @private
|
|
198
198
|
*/
|
|
199
|
-
async getExistsRedirect(req, siteName) {
|
|
199
|
+
async getExistsRedirect(req, siteName, requestLocale) {
|
|
200
200
|
if (!this.redirectsService) {
|
|
201
201
|
return undefined;
|
|
202
202
|
}
|
|
203
203
|
const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
|
|
204
204
|
const normalizedPath = incomingURL.replace(/\/*$/gi, '').toLowerCase();
|
|
205
205
|
const redirects = await this.redirectsService.fetchRedirects(siteName);
|
|
206
|
-
// locale of current request (from URL, headers or otherwise), used to match versioned redirect rules
|
|
207
|
-
const requestLocale = this.getLanguage(req);
|
|
206
|
+
// using locale of current request (from URL, headers or otherwise), used to match versioned redirect rules
|
|
208
207
|
const matchedLocaleRedirect = this.matchRedirectItemRedirect(redirects, requestLocale, normalizedPath);
|
|
209
208
|
if (matchedLocaleRedirect) {
|
|
210
209
|
return matchedLocaleRedirect;
|
|
@@ -278,16 +277,17 @@ export class RedirectsProxy extends ProxyBase {
|
|
|
278
277
|
* Processes redirect rules from redirect items (language-versioned)
|
|
279
278
|
* @param {RedirectResult[]} redirects redirect entries from Edge
|
|
280
279
|
* @param {string} locale current request locale
|
|
281
|
-
* @param {string} currentPath current request path
|
|
280
|
+
* @param {string} currentPath current request path
|
|
282
281
|
* @returns {RedirectResult | undefined} matched redirect item redirect result or undefined
|
|
283
282
|
* @private
|
|
284
283
|
*/
|
|
285
284
|
matchRedirectItemRedirect(redirects, locale, currentPath) {
|
|
285
|
+
const nonLocalePath = currentPath.replace(new RegExp(`^\/?${locale}\/`, 'i'), '/');
|
|
286
286
|
return redirects.length
|
|
287
287
|
? redirects.find((redirect) => {
|
|
288
288
|
const patternPath = redirect.pattern.replace(/\/*$/g, '').toLowerCase();
|
|
289
289
|
// locale rules are easy and nice
|
|
290
|
-
return redirect.locale === locale && patternPath ===
|
|
290
|
+
return redirect.locale === locale && patternPath === nonLocalePath;
|
|
291
291
|
})
|
|
292
292
|
: undefined;
|
|
293
293
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/nextjs",
|
|
3
|
-
"version": "2.1.0-canary.
|
|
3
|
+
"version": "2.1.0-canary.9",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"url": "https://github.com/sitecore/content-sdk/issues"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@sitecore-content-sdk/analytics-core": "2.1.0-canary.
|
|
36
|
-
"@sitecore-content-sdk/personalize": "2.1.0-canary.
|
|
35
|
+
"@sitecore-content-sdk/analytics-core": "2.1.0-canary.9",
|
|
36
|
+
"@sitecore-content-sdk/personalize": "2.1.0-canary.9",
|
|
37
37
|
"@stylistic/eslint-plugin": "^5.2.2",
|
|
38
38
|
"@testing-library/dom": "^10.4.0",
|
|
39
39
|
"@testing-library/react": "^16.3.0",
|
|
@@ -91,10 +91,10 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@babel/parser": "^7.27.2",
|
|
94
|
-
"@sitecore-content-sdk/content": "2.1.0-canary.
|
|
95
|
-
"@sitecore-content-sdk/core": "2.1.0-canary.
|
|
96
|
-
"@sitecore-content-sdk/events": "2.1.0-canary.
|
|
97
|
-
"@sitecore-content-sdk/react": "2.1.0-canary.
|
|
94
|
+
"@sitecore-content-sdk/content": "2.1.0-canary.9",
|
|
95
|
+
"@sitecore-content-sdk/core": "2.1.0-canary.9",
|
|
96
|
+
"@sitecore-content-sdk/events": "2.1.0-canary.9",
|
|
97
|
+
"@sitecore-content-sdk/react": "2.1.0-canary.9",
|
|
98
98
|
"recast": "^0.23.11",
|
|
99
99
|
"regex-parser": "^2.3.1",
|
|
100
100
|
"sync-disk-cache": "^2.1.0"
|
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
},
|
|
179
179
|
"description": "",
|
|
180
180
|
"types": "types/index.d.ts",
|
|
181
|
-
"gitHead": "
|
|
181
|
+
"gitHead": "a4c0a74b11b414ca47e054ae302756a25547b4e0",
|
|
182
182
|
"files": [
|
|
183
183
|
"dist",
|
|
184
184
|
"types",
|
|
@@ -35,7 +35,7 @@ export declare class RedirectsProxy extends ProxyBase {
|
|
|
35
35
|
* @returns Promise<RedirectInfo | undefined>
|
|
36
36
|
* @private
|
|
37
37
|
*/
|
|
38
|
-
protected getExistsRedirect(req: NextRequest, siteName: string): Promise<RedirectResult | undefined>;
|
|
38
|
+
protected getExistsRedirect(req: NextRequest, siteName: string, requestLocale: string): Promise<RedirectResult | undefined>;
|
|
39
39
|
/**
|
|
40
40
|
* Matches redirect-map rules without a `locale` field against the incoming URL (static or regex patterns).
|
|
41
41
|
* @param {RedirectResult[]} redirects All redirects from the service (non-locale entries are filtered inside).
|
|
@@ -50,7 +50,7 @@ export declare class RedirectsProxy extends ProxyBase {
|
|
|
50
50
|
* Processes redirect rules from redirect items (language-versioned)
|
|
51
51
|
* @param {RedirectResult[]} redirects redirect entries from Edge
|
|
52
52
|
* @param {string} locale current request locale
|
|
53
|
-
* @param {string} currentPath current request path
|
|
53
|
+
* @param {string} currentPath current request path
|
|
54
54
|
* @returns {RedirectResult | undefined} matched redirect item redirect result or undefined
|
|
55
55
|
* @private
|
|
56
56
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirects-proxy.d.ts","sourceRoot":"","sources":["../../src/proxy/redirects-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EAItB,YAAY,EAEb,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAuB,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAM3C,KAAK,cAAc,GAAG,YAAY,GAAG;IAAE,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,eAAe,CAAC,GACxF,cAAc,CAAC,KAA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