create-sitecore-jss 22.1.0-canary.9 → 22.2.0-canary.2
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.
- package/dist/bin.js +69 -28
- package/dist/common/processes/install.js +9 -2
- package/dist/common/processes/transform.js +7 -2
- package/dist/init-runner.js +12 -8
- package/dist/initializers/angular/index.js +16 -0
- package/dist/initializers/angular/prompts.js +22 -1
- package/dist/initializers/angular-sxp/index.js +56 -0
- package/dist/initializers/angular-xmcloud/index.js +56 -0
- package/dist/initializers/node-xmcloud-proxy/index.js +32 -0
- package/dist/templates/angular/.env +5 -3
- package/dist/templates/angular/README.md +5 -45
- package/dist/templates/angular/angular.json +1 -6
- package/dist/templates/angular/package.json +43 -53
- package/dist/templates/angular/proxy.conf.js +5 -23
- package/dist/templates/angular/scripts/bootstrap.ts +5 -24
- package/dist/templates/angular/scripts/config/index.ts +28 -0
- package/dist/templates/angular/scripts/config/plugins/computed.ts +21 -0
- package/dist/templates/angular/scripts/config/plugins/fallback.ts +23 -0
- package/dist/templates/angular/scripts/config/plugins/package-json.ts +22 -0
- package/dist/templates/angular/scripts/config/plugins/scjssconfig.ts +29 -0
- package/dist/templates/angular/scripts/generate-config.ts +53 -73
- package/dist/templates/angular/scripts/generate-plugins.ts +28 -0
- package/dist/templates/angular/scripts/temp/gitignore +2 -0
- package/dist/templates/angular/scripts/update-graphql-fragment-data.ts +4 -2
- package/dist/templates/angular/server.bundle.ts +20 -2
- package/dist/templates/angular/src/app/app.module.ts +0 -2
- package/dist/templates/angular/src/app/components/app-components.shared.module.ts +4 -19
- package/dist/templates/angular/src/app/jss-context.server-side.service.ts +0 -2
- package/dist/templates/angular/src/app/lib/config.ts +16 -0
- package/dist/templates/angular/src/app/lib/dictionary-service-factory.ts +21 -13
- package/dist/templates/angular/src/app/lib/layout-service-factory.ts +20 -12
- package/dist/templates/angular/src/app/routing/layout/layout.component.html +1 -1
- package/dist/templates/angular/src/app/routing/layout/layout.component.ts +1 -2
- package/dist/templates/angular/src/app/routing/navigation/navigation.component.html +5 -6
- package/dist/templates/angular/src/app/routing/navigation/navigation.component.ts +1 -2
- package/dist/templates/angular/src/app/routing/routing.module.ts +14 -21
- package/dist/templates/angular/src/app/routing/scripts/scripts.component.html +1 -0
- package/dist/templates/angular/src/app/routing/scripts/scripts.component.ts +7 -0
- package/dist/templates/angular/src/app/routing/scripts/scripts.module.ts +8 -0
- package/dist/templates/angular/src/graphql-fragment-types.ts +0 -95
- package/dist/templates/angular/src/polyfills.ts +2 -6
- package/dist/templates/angular/src/test.ts +1 -6
- package/dist/templates/angular/tsconfig.json +7 -2
- package/dist/templates/angular-sxp/package.json +12 -0
- package/dist/templates/angular-sxp/proxy.conf.js +43 -0
- package/dist/templates/angular-sxp/scripts/config/plugins/disconnected.ts +27 -0
- package/dist/templates/angular-sxp/src/app/components/app-components.shared.module.ts +35 -0
- package/dist/templates/{angular → angular-sxp}/src/app/jss-data-fetcher.service.ts +3 -1
- package/dist/templates/angular-sxp/src/app/routing/navigation/navigation.component.html +23 -0
- package/dist/templates/angular-sxp/src/app/routing/scripts/scripts.component.html +3 -0
- package/dist/templates/angular-sxp/src/app/routing/scripts/scripts.module.ts +9 -0
- package/dist/templates/{angular/src/app/routing → angular-sxp/src/app/routing/scripts}/visitor-identification/visitor-identification.component.ts +9 -3
- package/dist/templates/angular-sxp/src/graphql-fragment-types.ts +219 -0
- package/dist/templates/angular-xmcloud/.env +8 -0
- package/dist/templates/angular-xmcloud/package.json +10 -0
- package/dist/templates/angular-xmcloud/scripts/config/plugins/xmcloud.ts +23 -0
- package/dist/templates/angular-xmcloud/scripts/proxy-build.ts +15 -0
- package/dist/templates/angular-xmcloud/src/app/lib/config.ts +15 -0
- package/dist/templates/angular-xmcloud/src/app/lib/graphql-client-factory.ts +44 -0
- package/dist/templates/nextjs/next.config.js +5 -0
- package/dist/templates/nextjs/package.json +7 -6
- package/dist/templates/nextjs/src/lib/next-config/plugins/cors-header.js +0 -9
- package/dist/templates/nextjs/src/pages/[[...path]].tsx +1 -13
- package/dist/templates/nextjs-styleguide/package.json +1 -1
- package/dist/templates/nextjs-sxa/src/assets/sass/components/title/_component-title.scss +19 -13
- package/dist/templates/nextjs-sxa/src/components/Image.tsx +22 -12
- package/dist/templates/nextjs-sxa/src/components/Promo.tsx +1 -1
- package/dist/templates/nextjs-sxa/src/components/Title.tsx +10 -13
- package/dist/templates/nextjs-xmcloud/package.json +1 -1
- package/dist/templates/nextjs-xmcloud/src/Scripts.tsx +2 -0
- package/dist/templates/nextjs-xmcloud/src/lib/dictionary-service-factory.ts +46 -0
- package/dist/templates/nextjs-xmcloud/src/lib/graphql-editing-service.ts +9 -0
- package/dist/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts +6 -5
- package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/personalize.ts +7 -3
- package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/preview-mode.ts +72 -0
- package/dist/templates/nextjs-xmcloud/src/pages/api/editing/render.ts +46 -0
- package/dist/templates/node-headless-ssr-experience-edge/package.json +2 -2
- package/dist/templates/node-headless-ssr-proxy/package.json +4 -4
- package/dist/templates/node-xmcloud-proxy/.env +8 -0
- package/dist/templates/node-xmcloud-proxy/README.md +36 -0
- package/dist/templates/node-xmcloud-proxy/package.json +25 -0
- package/dist/templates/node-xmcloud-proxy/src/config.ts +19 -0
- package/dist/templates/node-xmcloud-proxy/src/index.ts +161 -0
- package/dist/templates/node-xmcloud-proxy/src/types.ts +59 -0
- package/dist/templates/node-xmcloud-proxy/tsconfig.json +22 -0
- package/dist/templates/react/package.json +5 -5
- package/dist/templates/react-native/package.json +4 -4
- package/dist/templates/vue/package.json +4 -4
- package/package.json +4 -4
- /package/dist/templates/angular/src/app/lib/{client-factory.ts → graphql-client-factory.ts} +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/component-content/Styleguide/ContentReuse/LoremIpsumContentBlock/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/component-content/gitignore +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/content/Styleguide/ContentListField/Item1/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/content/Styleguide/ContentListField/Item2/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/content/Styleguide/EditFrameDemo/Item1/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/content/Styleguide/EditFrameDemo/Item2/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/content/Styleguide/ItemLinkField/Item1/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/content/Styleguide/ItemLinkField/Item2/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/content/gitignore +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/dictionary/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/dictionary/{{language}}.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/media/files/jss.pdf +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/media/img/jss_logo.png +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/media/img/sc_logo.png +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/graphql/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/graphql/sample-1/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/graphql/sample-2/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/styleguide/custom-route-type/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/styleguide/en.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/styleguide/{{language}}.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/data/routes/{{language}}.yml +0 -0
- /package/dist/templates/{angular → angular-sxp}/scripts/disconnected-mode-proxy.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/scripts/lint-yml.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/config/{{appName}}.config +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/component-content.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/Styleguide-Layout-Reuse.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/Styleguide-Layout-Tabs-Tab.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/Styleguide-Layout-Tabs.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/Styleguide-Layout.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/Styleguide-Multilingual.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/Styleguide-Section.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/content-block.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/graph-ql-connected-demo.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/graph-ql-integrated-demo.sitecore.graphql +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/graph-ql-integrated-demo.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/graph-ql-layout.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-angular-lazy-loading.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-component-params.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-custom-route-type.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-edit-frame.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-checkbox.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-content-list.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-custom.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-date.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-file.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-image.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-item-link.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-link.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-number.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-rich-text.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-field-usage-text.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-route-fields.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-sitecore-context.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/components/styleguide-tracking.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/config.js +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/content.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/dictionary.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/placeholders.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/routes.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/templates/Styleguide-Explanatory-Component.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/templates/styleguide-content-list-template.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/templates/styleguide-edit-frame-list-item-template.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/definitions/templates/styleguide-item-link-template.sitecore.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/gitignore +0 -0
- /package/dist/templates/{angular → angular-sxp}/sitecore/pipelines/example.patch.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/graph-ql-connected-demo/graph-ql-connected-demo.component.graphql +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/graph-ql-connected-demo/graph-ql-connected-demo.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/graph-ql-connected-demo/graph-ql-connected-demo.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/graph-ql-integrated-demo/graph-ql-integrated-demo.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/graph-ql-integrated-demo/graph-ql-integrated-demo.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/graph-ql-layout/graph-ql-layout.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/graph-ql-layout/graph-ql-layout.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/shared/styleguide-specimen/styleguide-specimen.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-angular-lazy-loading/styleguide-angular-lazy-loading.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-angular-lazy-loading/styleguide-angular-lazy-loading.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-angular-lazy-loading/styleguide-angular-lazy-loading.module.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-component-params/styleguide-component-params.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-component-params/styleguide-component-params.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-custom-route-type/styleguide-custom-route-type.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-custom-route-type/styleguide-custom-route-type.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-edit-frame/styleguide-edit-frame.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-edit-frame/styleguide-edit-frame.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-checkbox/styleguide-field-usage-checkbox.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-checkbox/styleguide-field-usage-checkbox.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-content-list/styleguide-field-usage-content-list.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-content-list/styleguide-field-usage-content-list.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-custom/styleguide-field-usage-custom.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-custom/styleguide-field-usage-custom.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-date/styleguide-field-usage-date.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-date/styleguide-field-usage-date.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-file/styleguide-field-usage-file.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-file/styleguide-field-usage-file.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-image/styleguide-field-usage-image.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-image/styleguide-field-usage-image.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-item-link/styleguide-field-usage-item-link.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-item-link/styleguide-field-usage-item-link.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-link/styleguide-field-usage-link.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-link/styleguide-field-usage-link.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-number/styleguide-field-usage-number.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-number/styleguide-field-usage-number.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-rich-text/styleguide-field-usage-rich-text.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-rich-text/styleguide-field-usage-rich-text.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-text/styleguide-field-usage-text.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-field-usage-text/styleguide-field-usage-text.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout/styleguide-layout.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout/styleguide-layout.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout-reuse/styleguide-layout-reuse.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout-reuse/styleguide-layout-reuse.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout-tabs/styleguide-layout-tabs.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout-tabs/styleguide-layout-tabs.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout-tabs-tab/styleguide-layout-tabs-tab.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-layout-tabs-tab/styleguide-layout-tabs-tab.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-multilingual/styleguide-multilingual.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-multilingual/styleguide-multilingual.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-route-fields/styleguide-route-fields.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-route-fields/styleguide-route-fields.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-section/styleguide-section.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-section/styleguide-section.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-sitecore-context/styleguide-sitecore-context.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-sitecore-context/styleguide-sitecore-context.component.ts +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-tracking/styleguide-tracking.component.html +0 -0
- /package/dist/templates/{angular → angular-sxp}/src/app/components/styleguide-tracking/styleguide-tracking.component.ts +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EditingScripts } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
1
2
|
// The BYOC bundle imports external (BYOC) components into the app and makes sure they are ready to be used
|
|
2
3
|
import BYOC from 'src/byoc';
|
|
3
4
|
import CdpPageView from 'components/CdpPageView';
|
|
@@ -9,6 +10,7 @@ const Scripts = (): JSX.Element => {
|
|
|
9
10
|
<BYOC />
|
|
10
11
|
<CdpPageView />
|
|
11
12
|
<FEAASScripts />
|
|
13
|
+
<EditingScripts />
|
|
12
14
|
</>
|
|
13
15
|
);
|
|
14
16
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DictionaryService,
|
|
3
|
+
RestDictionaryService,
|
|
4
|
+
GraphQLDictionaryService,
|
|
5
|
+
constants,
|
|
6
|
+
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
7
|
+
import config from 'temp/config';
|
|
8
|
+
import clientFactory from 'lib/graphql-client-factory';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Factory responsible for creating a DictionaryService instance
|
|
12
|
+
*/
|
|
13
|
+
export class DictionaryServiceFactory {
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} siteName site name
|
|
16
|
+
* @returns {DictionaryService} service instance
|
|
17
|
+
*/
|
|
18
|
+
create(siteName: string): DictionaryService {
|
|
19
|
+
return process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL
|
|
20
|
+
? new GraphQLDictionaryService({
|
|
21
|
+
siteName,
|
|
22
|
+
clientFactory,
|
|
23
|
+
/*
|
|
24
|
+
GraphQL endpoint may reach its rate limit with the amount of requests it receives and throw a rate limit error.
|
|
25
|
+
GraphQL Dictionary and Layout Services can handle rate limit errors from server and attempt a retry on requests.
|
|
26
|
+
For this, specify the number of 'retries' the GraphQL client will attempt.
|
|
27
|
+
By default it is set to 3. You can disable it by configuring it to 0 for this service.
|
|
28
|
+
|
|
29
|
+
Additionally, you have the flexibility to customize the retry strategy by passing a 'retryStrategy'.
|
|
30
|
+
By default it uses the `DefaultRetryStrategy` with exponential back-off factor of 2 and handles error codes 429,
|
|
31
|
+
502, 503, 504, 520, 521, 522, 523, 524, 'ECONNRESET', 'ETIMEDOUT' and 'EPROTO' . You can use this class or your own implementation of `RetryStrategy`.
|
|
32
|
+
*/
|
|
33
|
+
retries: (process.env.GRAPH_QL_SERVICE_RETRIES &&
|
|
34
|
+
parseInt(process.env.GRAPH_QL_SERVICE_RETRIES, 10)) as number,
|
|
35
|
+
useSiteQuery: true,
|
|
36
|
+
})
|
|
37
|
+
: new RestDictionaryService({
|
|
38
|
+
apiHost: config.sitecoreApiHost,
|
|
39
|
+
apiKey: config.sitecoreApiKey,
|
|
40
|
+
siteName,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** DictionaryServiceFactory singleton */
|
|
46
|
+
export const dictionaryServiceFactory = new DictionaryServiceFactory();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GraphQLEditingService } from '@sitecore-jss/sitecore-jss-nextjs/editing';
|
|
2
|
+
import clientFactory from 'lib/graphql-client-factory';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GraphQL Editing Service instance. Used to fetch editing data in Pages preview (editing) Metadata Edit Mode.
|
|
6
|
+
*/
|
|
7
|
+
export const graphQLEditingService = new GraphQLEditingService({
|
|
8
|
+
clientFactory,
|
|
9
|
+
});
|
|
@@ -7,12 +7,12 @@ import { siteResolver } from 'lib/site-resolver';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* This is the personalize middleware plugin for Next.js.
|
|
10
|
-
* It is used to enable Sitecore personalization of pages in Next.js.
|
|
10
|
+
* It is used to enable Sitecore personalization and A/B testing of pages in Next.js.
|
|
11
11
|
*
|
|
12
12
|
* The `PersonalizeMiddleware` will
|
|
13
|
-
* 1.
|
|
14
|
-
* 2. Based on the response,
|
|
15
|
-
* 3. Rewrite the response to the specific page variant.
|
|
13
|
+
* 1. Call Sitecore Experience Edge to get the personalization information about the page.
|
|
14
|
+
* 2. Based on the response, call Sitecore Personalize (with request/user context) to determine the page / component variant(s).
|
|
15
|
+
* 3. Rewrite the response to the specific page / component variant(s).
|
|
16
16
|
*/
|
|
17
17
|
class PersonalizePlugin implements MiddlewarePlugin {
|
|
18
18
|
private personalizeMiddleware: PersonalizeMiddleware;
|
|
@@ -30,7 +30,6 @@ class PersonalizePlugin implements MiddlewarePlugin {
|
|
|
30
30
|
(process.env.PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT &&
|
|
31
31
|
parseInt(process.env.PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT)) ||
|
|
32
32
|
400,
|
|
33
|
-
scope: process.env.NEXT_PUBLIC_PERSONALIZE_SCOPE,
|
|
34
33
|
},
|
|
35
34
|
// Configuration for your Sitecore CDP endpoint
|
|
36
35
|
cdpConfig: {
|
|
@@ -41,6 +40,8 @@ class PersonalizePlugin implements MiddlewarePlugin {
|
|
|
41
40
|
parseInt(process.env.PERSONALIZE_MIDDLEWARE_CDP_TIMEOUT)) ||
|
|
42
41
|
400,
|
|
43
42
|
},
|
|
43
|
+
// Optional Sitecore Personalize scope identifier.
|
|
44
|
+
scope: process.env.NEXT_PUBLIC_PERSONALIZE_SCOPE,
|
|
44
45
|
// This function determines if the middleware should be turned off.
|
|
45
46
|
// IMPORTANT: You should implement based on your cookie consent management solution of choice.
|
|
46
47
|
// You may wish to keep it disabled while in development mode.
|
|
@@ -16,12 +16,16 @@ class PersonalizePlugin implements Plugin {
|
|
|
16
16
|
? context.params.path.join('/')
|
|
17
17
|
: context.params.path ?? '/';
|
|
18
18
|
|
|
19
|
-
// Get variant for personalization (from path)
|
|
19
|
+
// Get variant(s) for personalization (from path)
|
|
20
20
|
const personalizeData = getPersonalizedRewriteData(path);
|
|
21
21
|
|
|
22
|
-
// Modify layoutData to use specific variant instead of default
|
|
22
|
+
// Modify layoutData to use specific variant(s) instead of default
|
|
23
23
|
// This will also set the variantId on the Sitecore context so that it is accessible here
|
|
24
|
-
personalizeLayout(
|
|
24
|
+
personalizeLayout(
|
|
25
|
+
props.layoutData,
|
|
26
|
+
personalizeData.variantId,
|
|
27
|
+
personalizeData.componentVariantIds
|
|
28
|
+
);
|
|
25
29
|
|
|
26
30
|
return props;
|
|
27
31
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
|
|
2
|
+
import {
|
|
3
|
+
SiteInfo,
|
|
4
|
+
personalizeLayout,
|
|
5
|
+
getGroomedVariantIds,
|
|
6
|
+
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
7
|
+
import {
|
|
8
|
+
editingDataService,
|
|
9
|
+
isEditingMetadataPreviewData,
|
|
10
|
+
} from '@sitecore-jss/sitecore-jss-nextjs/editing';
|
|
11
|
+
import { SitecorePageProps } from 'lib/page-props';
|
|
12
|
+
import { graphQLEditingService } from 'lib/graphql-editing-service';
|
|
13
|
+
import { Plugin } from '..';
|
|
14
|
+
|
|
15
|
+
class PreviewModePlugin implements Plugin {
|
|
16
|
+
order = 1;
|
|
17
|
+
|
|
18
|
+
async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
|
|
19
|
+
if (!context.preview) return props;
|
|
20
|
+
|
|
21
|
+
// If we're in Pages preview (editing) Metadata Edit Mode, prefetch the editing data
|
|
22
|
+
if (isEditingMetadataPreviewData(context.previewData)) {
|
|
23
|
+
const { site, itemId, language, version, variantIds } = context.previewData;
|
|
24
|
+
|
|
25
|
+
const data = await graphQLEditingService.fetchEditingData({
|
|
26
|
+
siteName: site,
|
|
27
|
+
itemId,
|
|
28
|
+
language,
|
|
29
|
+
version,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!data) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Unable to fetch editing data for preview ${JSON.stringify(context.previewData)}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
props.site = data.layoutData.sitecore.context.site as SiteInfo;
|
|
39
|
+
props.locale = context.previewData.language;
|
|
40
|
+
props.layoutData = data.layoutData;
|
|
41
|
+
props.dictionary = data.dictionary;
|
|
42
|
+
props.headLinks = [];
|
|
43
|
+
const personalizeData = getGroomedVariantIds(variantIds);
|
|
44
|
+
personalizeLayout(
|
|
45
|
+
props.layoutData,
|
|
46
|
+
personalizeData.variantId,
|
|
47
|
+
personalizeData.componentVariantIds
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return props;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// If we're in preview (editing) Chromes Edit Mode, use data already sent along with the editing request
|
|
54
|
+
// This mode is used by the Experience Editor.
|
|
55
|
+
// In Pages it's treated as a legacy mode but still supported for backward compatibility.
|
|
56
|
+
const data = await editingDataService.getEditingData(context.previewData);
|
|
57
|
+
if (!data) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Unable to get editing data for preview ${JSON.stringify(context.previewData)}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
props.site = data.layoutData.sitecore.context.site as SiteInfo;
|
|
63
|
+
props.locale = data.language;
|
|
64
|
+
props.layoutData = data.layoutData;
|
|
65
|
+
props.dictionary = data.dictionary;
|
|
66
|
+
props.headLinks = [];
|
|
67
|
+
|
|
68
|
+
return props;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const previewModePlugin = new PreviewModePlugin();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EditingRenderMiddleware } from '@sitecore-jss/sitecore-jss-nextjs/editing';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This Next.js API route is used to handle GET and POST requests from Sitecore editors.
|
|
5
|
+
* GET requests are used with Metadata editing mode while POST ones are used with Chromes(legacy) mode.
|
|
6
|
+
* This route should match the `serverSideRenderingEngineEndpointUrl` in your Sitecore configuration,
|
|
7
|
+
* which is set to "http://<rendering_host>/api/editing/render" by default (see the settings item under /sitecore/content/<your/site/path>/Settings/Site Grouping).
|
|
8
|
+
*
|
|
9
|
+
* For Metadata mode, the `EditingRenderMiddleware` will
|
|
10
|
+
* 1. Extract data about the route we need to rendr from the Sitecore editor GET request
|
|
11
|
+
* 2. Enable Next.js Preview Mode, passing the route data as preview data
|
|
12
|
+
* 3. Redirect the request to the route, passing along the Preview Mode cookies.
|
|
13
|
+
* This allows retrieval of the editing data in preview context (via an `EditingDataService`) - see `SitecorePagePropsFactory`
|
|
14
|
+
* 4. The redirected request will render the page with editing markup in place
|
|
15
|
+
*
|
|
16
|
+
* For Chromes(legacy) mode, the `EditingRenderMiddleware` will
|
|
17
|
+
* 1. Extract editing data from the Sitecore editor POST request
|
|
18
|
+
* 2. Stash this data (for later use in the page render request) via an `EditingDataService`, which returns a key for retrieval
|
|
19
|
+
* 3. Enable Next.js Preview Mode, passing our stashed editing data key as preview data
|
|
20
|
+
* 4. Invoke the actual page render request, passing along the Preview Mode cookies.
|
|
21
|
+
* This allows retrieval of the editing data in preview context (via an `EditingDataService`) - see `SitecorePagePropsFactory`
|
|
22
|
+
* 5. Return the rendered page HTML to the Sitecore editor
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* [Chromes mode only] For Vercel deployments:
|
|
28
|
+
* if you experience crashes in editing, you may need to use VercelEditingDataCache or a custom Redis data cache implementation with EditingRenderMiddleware
|
|
29
|
+
* Please refer to documentation for a detailed guide.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// [Chromes mode only] Bump body size limit (1mb by default) and disable response limit for Sitecore editor payloads
|
|
33
|
+
// See https://nextjs.org/docs/api-routes/request-helpers#custom-config
|
|
34
|
+
export const config = {
|
|
35
|
+
api: {
|
|
36
|
+
bodyParser: {
|
|
37
|
+
sizeLimit: '2mb',
|
|
38
|
+
},
|
|
39
|
+
responseLimit: false,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Wire up the EditingRenderMiddleware handler
|
|
44
|
+
const handler = new EditingRenderMiddleware().getHandler();
|
|
45
|
+
|
|
46
|
+
export default handler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-headless-ssr-experience-edge-sample",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.2.0-canary",
|
|
4
4
|
"description": "Node server-side-rendering sample for running JSS apps under Node hosting using Experience Edge",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "ts-node ./src/index.ts"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"homepage": "https://jss.sitecore.com",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@sitecore-jss/sitecore-jss": "~22.
|
|
22
|
+
"@sitecore-jss/sitecore-jss": "~22.2.0-canary",
|
|
23
23
|
"compression": "^1.7.4",
|
|
24
24
|
"express": "^4.18.2",
|
|
25
25
|
"dotenv": "^16.0.3"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-headless-ssr-proxy-sample",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.2.0-canary",
|
|
4
4
|
"description": "Node server-side-rendering proxy sample for running JSS apps under Node hosting",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "ts-node ./src/index.ts"
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"homepage": "https://jss.sitecore.com",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@sitecore-jss/sitecore-jss": "~22.
|
|
23
|
-
"@sitecore-jss/sitecore-jss-proxy": "~22.
|
|
22
|
+
"@sitecore-jss/sitecore-jss": "~22.2.0-canary",
|
|
23
|
+
"@sitecore-jss/sitecore-jss-proxy": "~22.2.0-canary",
|
|
24
24
|
"agentkeepalive": "^4.2.1",
|
|
25
25
|
"compression": "~1.7.4",
|
|
26
26
|
"express": "~4.19.2",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@types/compression": "^1.7.2",
|
|
32
32
|
"@types/express": "^4.17.17",
|
|
33
33
|
"@types/memory-cache": "^0.2.2",
|
|
34
|
-
"@types/node": "^
|
|
34
|
+
"@types/node": "^20.14.2",
|
|
35
35
|
"ts-node": "^10.9.1",
|
|
36
36
|
"typescript": "~4.9.5"
|
|
37
37
|
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Your proxy port (default: 3001)
|
|
2
|
+
PROXY_PORT=
|
|
3
|
+
|
|
4
|
+
# Your proxy server bundle path
|
|
5
|
+
PROXY_BUNDLE_PATH=
|
|
6
|
+
|
|
7
|
+
# Set the DEBUG environment variable to 'sitecore-jss:*,sitecore-jss:proxy,http-proxy-middleware*' to see all logs:
|
|
8
|
+
#DEBUG=sitecore-jss:*,http-proxy-middleware*
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Node XM Cloud Proxy
|
|
2
|
+
|
|
3
|
+
> Sitecore JSS Proxy for XM Cloud is considered experimental.
|
|
4
|
+
|
|
5
|
+
[Documentation](<TODO>)
|
|
6
|
+
|
|
7
|
+
This is a sample setup showing one of how you can configure XM Cloud rendering server.
|
|
8
|
+
|
|
9
|
+
## Pre-requisites
|
|
10
|
+
|
|
11
|
+
1. SPA sample supports XM Cloud out of the box.
|
|
12
|
+
|
|
13
|
+
1. Build your SPA app bundle with `jss build`. The build output should be placed in the `dist` folder.
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
Open `config.js` and specify your application settings.
|
|
18
|
+
|
|
19
|
+
### Environment Variables
|
|
20
|
+
|
|
21
|
+
The following environment variables can be set to configure the Proxy sample instead of modifying `config.js`. You can use the `.env` file located in the root of the app or set these directly in the environment (for example, in containers).
|
|
22
|
+
|
|
23
|
+
| Parameter | Description |
|
|
24
|
+
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
25
|
+
| `PROXY_BUNDLE_PATH` | Path to the JSS SPA app's `server.bundle.js`. Default can be seen in [config.js](./config.js) file. |
|
|
26
|
+
| `PROXY_PORT` | Optional. Port which will be used when start sample. Default can be seen in [config.js](./config.js) file. |
|
|
27
|
+
| `DEBUG` | Optional. Debug level for the proxy. Set the DEBUG environment variable to 'sitecore-jss:*,proxy*,http-proxy-middleware*' to see all logs. |
|
|
28
|
+
|
|
29
|
+
## Build & run
|
|
30
|
+
|
|
31
|
+
1. Run `npm install`
|
|
32
|
+
|
|
33
|
+
1. Run `npm run start`
|
|
34
|
+
|
|
35
|
+
You should be able to see the following message:
|
|
36
|
+
`server listening on port 3001!`.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-xmcloud-sample",
|
|
3
|
+
"version": "22.1.0-canary",
|
|
4
|
+
"description": "Node XM Cloud Proxy sample for running XM Cloud JSS SPA apps",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Sitecore Corporation",
|
|
7
|
+
"url": "https://jss.sitecore.com"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "ts-node ./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"compression": "^1.7.4",
|
|
14
|
+
"express": "^4.18.2",
|
|
15
|
+
"dotenv": "^16.0.3",
|
|
16
|
+
"http-proxy-middleware": "^3.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@sitecore-jss/sitecore-jss": "~22.1.0-canary",
|
|
20
|
+
"@types/compression": "^1.7.2",
|
|
21
|
+
"@types/express": "^4.17.17",
|
|
22
|
+
"ts-node": "^10.9.1",
|
|
23
|
+
"typescript": "~4.9.5"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Config, ServerBundle } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The server.bundle.js file from your pre-built SPA app.
|
|
5
|
+
*/
|
|
6
|
+
const bundlePath = process.env.PROXY_BUNDLE_PATH || `../dist/server.bundle`;
|
|
7
|
+
|
|
8
|
+
const serverBundle: ServerBundle = require(bundlePath);
|
|
9
|
+
|
|
10
|
+
export const config: Config = {
|
|
11
|
+
/**
|
|
12
|
+
* The require'd server.bundle.js file from your pre-built SPA app.
|
|
13
|
+
*/
|
|
14
|
+
serverBundle,
|
|
15
|
+
/**
|
|
16
|
+
* Port which will be used when start the proxy
|
|
17
|
+
*/
|
|
18
|
+
port: process.env.PROXY_PORT || 3001,
|
|
19
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import express, { Response } from 'express';
|
|
3
|
+
import compression from 'compression';
|
|
4
|
+
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
5
|
+
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
6
|
+
import { config } from './config';
|
|
7
|
+
|
|
8
|
+
const server = express();
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
renderView,
|
|
12
|
+
parseRouteUrl,
|
|
13
|
+
dictionaryServiceFactory,
|
|
14
|
+
layoutServiceFactory,
|
|
15
|
+
} = config.serverBundle;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Required server bundle properties
|
|
19
|
+
*/
|
|
20
|
+
const requiredProperties = [
|
|
21
|
+
'renderView',
|
|
22
|
+
'parseRouteUrl',
|
|
23
|
+
'clientFactory',
|
|
24
|
+
'siteName',
|
|
25
|
+
'defaultLanguage',
|
|
26
|
+
'layoutServiceFactory',
|
|
27
|
+
'dictionaryServiceFactory',
|
|
28
|
+
'graphQLEndpointPath',
|
|
29
|
+
'graphQLEndpoint',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const missingProperties = requiredProperties.filter((property) => !config.serverBundle[property]);
|
|
33
|
+
|
|
34
|
+
if (missingProperties.length > 0) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`ERROR: The serverBundle should export the following properties: ${missingProperties.join(
|
|
37
|
+
', '
|
|
38
|
+
)}. Please check your server bundle.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const layoutService = layoutServiceFactory.create();
|
|
43
|
+
|
|
44
|
+
const dictionaryService = dictionaryServiceFactory.create();
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Parse requested url in order to detect current route and language
|
|
48
|
+
* @param {string} reqRoute requested route
|
|
49
|
+
*/
|
|
50
|
+
const getRouteParams = (reqRoute: string) => {
|
|
51
|
+
const routeParams = parseRouteUrl(reqRoute);
|
|
52
|
+
let lang;
|
|
53
|
+
let route;
|
|
54
|
+
|
|
55
|
+
if (routeParams) {
|
|
56
|
+
route = routeParams.sitecoreRoute || '/';
|
|
57
|
+
|
|
58
|
+
if (!route.startsWith('/')) {
|
|
59
|
+
route = `/${route}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
lang = routeParams.lang || '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { route, lang };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Handle unexpected error
|
|
70
|
+
* @param {Response} res server response
|
|
71
|
+
* @param {Error} err error
|
|
72
|
+
*/
|
|
73
|
+
const handleError = (res: Response, err: unknown) => {
|
|
74
|
+
debug.proxy('response error %o', err);
|
|
75
|
+
|
|
76
|
+
res.status(500).send('Internal Server Error');
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// enable gzip compression for appropriate file types
|
|
80
|
+
server.use(compression());
|
|
81
|
+
|
|
82
|
+
// turn off x-powered-by http header
|
|
83
|
+
server.settings['x-powered-by'] = false;
|
|
84
|
+
|
|
85
|
+
// Serve static app assets from local /dist folder
|
|
86
|
+
server.use(
|
|
87
|
+
'/dist',
|
|
88
|
+
express.static('dist', {
|
|
89
|
+
fallthrough: false, // force 404 for unknown assets under /dist
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Proxy browser GraphQL requests to the Sitecore GraphQL endpoint
|
|
95
|
+
*/
|
|
96
|
+
server.use(
|
|
97
|
+
config.serverBundle.graphQLEndpointPath,
|
|
98
|
+
createProxyMiddleware({
|
|
99
|
+
target: config.serverBundle.graphQLEndpoint,
|
|
100
|
+
changeOrigin: true,
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
server.use(async (req, res) => {
|
|
105
|
+
debug.proxy(`performing SSR for ${req.originalUrl}`);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const { route, lang } = getRouteParams(req.originalUrl);
|
|
109
|
+
|
|
110
|
+
if (!route) {
|
|
111
|
+
debug.proxy('no route detected, returning 404');
|
|
112
|
+
|
|
113
|
+
res.sendStatus(404);
|
|
114
|
+
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Language is required. In case it's not specified in the requested URL, fallback to the default language from the app configuration.
|
|
119
|
+
const layoutData = await layoutService.fetchLayoutData(
|
|
120
|
+
route,
|
|
121
|
+
lang || config.serverBundle.defaultLanguage
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const viewBag = { dictionary: {} };
|
|
125
|
+
|
|
126
|
+
viewBag.dictionary = await dictionaryService.fetchDictionaryData(
|
|
127
|
+
layoutData.sitecore.context.language || config.serverBundle.defaultLanguage
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
renderView(
|
|
131
|
+
(err, result) => {
|
|
132
|
+
if (err) {
|
|
133
|
+
handleError(res, err);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!result) {
|
|
138
|
+
debug.proxy('no result returned from renderView, returning 204');
|
|
139
|
+
|
|
140
|
+
res.status(204).send();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const statusCode = layoutData.sitecore.route ? 200 : 404;
|
|
145
|
+
|
|
146
|
+
debug.proxy('sending response with status %s', statusCode);
|
|
147
|
+
|
|
148
|
+
res.status(statusCode).send(result.html);
|
|
149
|
+
},
|
|
150
|
+
route,
|
|
151
|
+
layoutData,
|
|
152
|
+
viewBag
|
|
153
|
+
);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
handleError(res, err);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
server.listen(config.port, () => {
|
|
160
|
+
console.log(`server listening on port ${config.port}!`);
|
|
161
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { GraphQLRequestClientFactory } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
import { DictionaryService } from '@sitecore-jss/sitecore-jss/i18n';
|
|
3
|
+
import { LayoutService, LayoutServiceData } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
|
+
|
|
5
|
+
interface ServerResponse {
|
|
6
|
+
/**
|
|
7
|
+
* The rendered HTML to return to the client
|
|
8
|
+
*/
|
|
9
|
+
html: string;
|
|
10
|
+
/**
|
|
11
|
+
* Set the HTTP status code. If not set, the status code returned from Layout Service is returned.
|
|
12
|
+
*/
|
|
13
|
+
status?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Sets a redirect URL, causing the reply to send a HTTP redirect instead of the HTML content.
|
|
16
|
+
* Note: when using this you must set the status code to 301 or 302.
|
|
17
|
+
*/
|
|
18
|
+
redirect?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare type AppRenderer = (
|
|
22
|
+
callback: (error: Error | null, result: ServerResponse | null) => void,
|
|
23
|
+
path: string,
|
|
24
|
+
/**
|
|
25
|
+
* Data returned by Layout Service. If the route does not exist, null.
|
|
26
|
+
*/
|
|
27
|
+
layoutData: LayoutServiceData,
|
|
28
|
+
viewBag: {
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
dictionary: { [key: string]: string };
|
|
31
|
+
}
|
|
32
|
+
) => void;
|
|
33
|
+
|
|
34
|
+
declare type RouteUrlParser = (
|
|
35
|
+
url: string
|
|
36
|
+
) => {
|
|
37
|
+
sitecoreRoute?: string;
|
|
38
|
+
lang?: string;
|
|
39
|
+
qsParams?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface ServerBundle {
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
renderView: AppRenderer;
|
|
45
|
+
parseRouteUrl: RouteUrlParser;
|
|
46
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
47
|
+
siteName: string;
|
|
48
|
+
defaultLanguage: string;
|
|
49
|
+
layoutServiceFactory: { create: () => LayoutService };
|
|
50
|
+
dictionaryServiceFactory: { create: () => DictionaryService };
|
|
51
|
+
graphQLEndpointPath: string;
|
|
52
|
+
graphQLEndpoint: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Config {
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
port: string | number;
|
|
58
|
+
serverBundle: ServerBundle;
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"newLine": "LF",
|
|
4
|
+
"emitDecoratorMetadata": true,
|
|
5
|
+
"experimentalDecorators": true,
|
|
6
|
+
"noFallthroughCasesInSwitch": true,
|
|
7
|
+
"rootDir": ".",
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noImplicitAny": true,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true,
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"strictFunctionTypes": false,
|
|
16
|
+
"downlevelIteration": true,
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"allowSyntheticDefaultImports": true
|
|
20
|
+
},
|
|
21
|
+
"exclude": ["node_modules", "dist"]
|
|
22
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<%- appName %>",
|
|
3
3
|
"description": "Application utilizing Sitecore JavaScript Services and React (create-react-app).",
|
|
4
|
-
"version": "22.
|
|
4
|
+
"version": "22.2.0-canary",
|
|
5
5
|
"private": true,
|
|
6
6
|
"config": {
|
|
7
7
|
"appName": "<%- appName %>",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@apollo/client": "^3.7.1",
|
|
31
|
-
"@sitecore-jss/sitecore-jss-react": "~22.
|
|
31
|
+
"@sitecore-jss/sitecore-jss-react": "~22.2.0-canary",
|
|
32
32
|
"axios": "^1.2.0",
|
|
33
33
|
"bootstrap": "^5.2.3",
|
|
34
34
|
"cross-fetch": "^3.1.5",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"@babel/preset-env": "^7.20.2",
|
|
54
54
|
"@babel/preset-react": "^7.18.6",
|
|
55
55
|
"@babel/register": "~7.18.9",
|
|
56
|
-
"@sitecore-jss/sitecore-jss-cli": "~22.
|
|
57
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "~22.
|
|
58
|
-
"@sitecore-jss/sitecore-jss-rendering-host": "~22.
|
|
56
|
+
"@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
|
|
57
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
|
|
58
|
+
"@sitecore-jss/sitecore-jss-rendering-host": "~22.2.0-canary",
|
|
59
59
|
"babel-loader": "~9.1.0",
|
|
60
60
|
"babel-preset-react-app": "~10.0.1",
|
|
61
61
|
"chalk": "~4.1.2",
|