create-content-sdk-app 1.4.0-canary.8 → 1.4.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type NextRequest, type NextFetchEvent
|
|
1
|
+
import { type NextRequest, type NextFetchEvent } from 'next/server';
|
|
2
2
|
import {
|
|
3
3
|
defineMiddleware,
|
|
4
4
|
MultisiteMiddleware,
|
|
@@ -9,13 +9,8 @@ import sites from '.sitecore/sites.json';
|
|
|
9
9
|
import scConfig from 'sitecore.config';
|
|
10
10
|
|
|
11
11
|
export function middleware(req: NextRequest, ev: NextFetchEvent) {
|
|
12
|
-
// Skip middlewares only if neither Edge nor local API configuration is available.
|
|
13
|
-
// Middlewares can work with either Edge (contextId) or local (apiHost/apiKey) configuration.
|
|
14
|
-
if (!scConfig.api?.edge?.contextId && !scConfig.api?.local?.apiHost) {
|
|
15
|
-
return NextResponse.next();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
12
|
// Instantiate middlewares - they will use Edge config if available, otherwise fall back to local config
|
|
13
|
+
// Each middleware will skip processing if required API configuration is not available
|
|
19
14
|
const multisite = new MultisiteMiddleware({
|
|
20
15
|
/**
|
|
21
16
|
* List of sites for site resolver to work with
|
|
@@ -10,75 +10,78 @@ import sites from '.sitecore/sites.json';
|
|
|
10
10
|
import scConfig from 'sitecore.config';
|
|
11
11
|
import { routing } from './i18n/routing';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
export function middleware(req: NextRequest, ev: NextFetchEvent) {
|
|
14
|
+
// LocaleMiddleware and AppRouterMultisiteMiddleware must always run for App Router routing
|
|
15
|
+
const locale = new LocaleMiddleware({
|
|
16
|
+
/**
|
|
17
|
+
* List of sites for site resolver to work with
|
|
18
|
+
*/
|
|
19
|
+
sites,
|
|
20
|
+
/**
|
|
21
|
+
* List of all supported locales configured in routing.ts
|
|
22
|
+
*/
|
|
23
|
+
locales: routing.locales.slice(),
|
|
24
|
+
// This function determines if the middleware should be turned off on per-request basis.
|
|
25
|
+
// Certain paths are ignored by default (e.g. files and Next.js API routes), but you may wish to disable more.
|
|
26
|
+
// This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
27
|
+
// in multilanguage scenarios, we need locale middleware to always run first to ensure locale is set and used correctly by the rest of the middlewares
|
|
28
|
+
skip: () => false,
|
|
29
|
+
});
|
|
28
30
|
|
|
29
|
-
const multisite = new AppRouterMultisiteMiddleware({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
31
|
+
const multisite = new AppRouterMultisiteMiddleware({
|
|
32
|
+
/**
|
|
33
|
+
* List of sites for site resolver to work with
|
|
34
|
+
*/
|
|
35
|
+
sites,
|
|
36
|
+
...scConfig.multisite,
|
|
37
|
+
// This function determines if the middleware should be turned off on per-request basis.
|
|
38
|
+
// Certain paths are ignored by default (e.g. files and Next.js API routes), but you may wish to disable more.
|
|
39
|
+
// This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
40
|
+
skip: () => false,
|
|
41
|
+
});
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
// Instantiate middlewares - they will use Edge config if available, otherwise fall back to local config
|
|
44
|
+
// Each middleware will skip processing if required API configuration is not available
|
|
45
|
+
const redirects = new RedirectsMiddleware({
|
|
46
|
+
/**
|
|
47
|
+
* List of sites for site resolver to work with
|
|
48
|
+
*/
|
|
49
|
+
sites,
|
|
50
|
+
...scConfig.api.edge,
|
|
51
|
+
...scConfig.api.local,
|
|
52
|
+
...scConfig.redirects,
|
|
53
|
+
// This function determines if the middleware should be turned off on per-request basis.
|
|
54
|
+
// Certain paths are ignored by default (e.g. Next.js API routes), but you may wish to disable more.
|
|
55
|
+
// By default it is disabled while in development mode.
|
|
56
|
+
// This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
57
|
+
skip: () => false,
|
|
58
|
+
});
|
|
55
59
|
|
|
56
|
-
const personalize = new PersonalizeMiddleware({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
60
|
+
const personalize = new PersonalizeMiddleware({
|
|
61
|
+
/**
|
|
62
|
+
* List of sites for site resolver to work with
|
|
63
|
+
*/
|
|
64
|
+
sites,
|
|
65
|
+
...scConfig.api.edge,
|
|
66
|
+
...scConfig.personalize,
|
|
67
|
+
// This function determines if the middleware should be turned off on per-request basis.
|
|
68
|
+
// Certain paths are ignored by default (e.g. Next.js API routes), but you may wish to disable more.
|
|
69
|
+
// By default it is disabled while in development mode.
|
|
70
|
+
// This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
71
|
+
// NOTE: Personalize requires Edge configuration and cannot work with local containers.
|
|
72
|
+
// The middleware will disable itself if Edge config is not present.
|
|
73
|
+
skip: () => false,
|
|
74
|
+
// This is an example of how to provide geo data for personalization.
|
|
75
|
+
// The provided callback will be called on each request to extract geo data.
|
|
76
|
+
// extractGeoDataCb: () => {
|
|
77
|
+
// return {
|
|
78
|
+
// city: 'Athens',
|
|
79
|
+
// country: 'Greece',
|
|
80
|
+
// region: 'Attica',
|
|
81
|
+
// };
|
|
82
|
+
// },
|
|
83
|
+
});
|
|
80
84
|
|
|
81
|
-
export function middleware(req: NextRequest, ev: NextFetchEvent) {
|
|
82
85
|
return defineMiddleware(locale, multisite, redirects, personalize).exec(req, ev);
|
|
83
86
|
}
|
|
84
87
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-content-sdk-app",
|
|
3
|
-
"version": "1.4.0-canary.
|
|
3
|
+
"version": "1.4.0-canary.9",
|
|
4
4
|
"description": "Sitecore Content SDK initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"ts-node": "^10.9.2",
|
|
71
71
|
"typescript": "~5.8.3"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "d6d456ba7f417687b97043650089598078a8b5c1"
|
|
74
74
|
}
|