create-sitecore-jss 22.2.0-canary.10 → 22.2.0-canary.12
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/templates/angular/.env +4 -0
- package/dist/templates/angular/package.json +0 -2
- package/dist/templates/angular/scripts/config/plugins/fallback.ts +0 -1
- package/dist/templates/angular/scripts/generate-config.ts +14 -3
- package/dist/templates/angular/scripts/update-graphql-fragment-data.ts +20 -28
- package/dist/templates/angular/server.bundle.ts +4 -5
- package/dist/templates/angular/src/app/JssState.ts +2 -2
- package/dist/templates/angular/src/app/app.module.ts +2 -0
- package/dist/templates/angular/src/app/lib/dictionary-service-factory.ts +4 -1
- package/dist/templates/angular/src/app/lib/graphql-client-factory/config.ts +21 -0
- package/dist/templates/angular/src/app/lib/graphql-client-factory/index.ts +16 -0
- package/dist/templates/angular/src/app/lib/layout-service-factory.ts +1 -1
- package/dist/templates/angular/src/app/routing/layout/layout.component.ts +10 -9
- package/dist/templates/angular-sxp/scripts/config/plugins/disconnected.ts +4 -2
- package/dist/templates/angular-xmcloud/.env +6 -0
- package/dist/templates/angular-xmcloud/scripts/config/plugins/xmcloud.ts +16 -0
- package/dist/templates/angular-xmcloud/src/app/jss-link.service.ts +14 -12
- package/dist/templates/angular-xmcloud/src/app/lib/config.ts +2 -0
- package/dist/templates/angular-xmcloud/src/app/lib/graphql-client-factory/config.ts +58 -0
- package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.html +1 -1
- package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.ts +35 -42
- package/dist/templates/nextjs/scripts/config/plugins/fallback.ts +0 -1
- package/dist/templates/nextjs/scripts/generate-config.ts +8 -1
- package/dist/templates/nextjs-styleguide/scripts/config/plugins/disconnected.ts +1 -0
- package/dist/templates/node-xmcloud-proxy/package.json +2 -2
- package/dist/templates/node-xmcloud-proxy/src/config.ts +1 -1
- package/dist/templates/node-xmcloud-proxy/src/index.ts +28 -4
- package/dist/templates/node-xmcloud-proxy/src/types.ts +5 -3
- package/dist/templates/react/scripts/generate-config.js +10 -3
- package/dist/templates/vue/scripts/generate-config.js +5 -0
- package/package.json +2 -2
- package/dist/templates/angular/src/app/lib/graphql-client-factory.ts +0 -28
- package/dist/templates/angular-xmcloud/src/app/lib/graphql-client-factory.ts +0 -44
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# ====== Sitecore Preview / Delivery Edge ======
|
|
2
|
+
|
|
1
3
|
# Your Sitecore API key is needed to build the app. Typically, the API key is
|
|
2
4
|
# defined in `scjssconfig.json` (as `sitecore.apiKey`). This file may not exist
|
|
3
5
|
# when building locally (if you've never run `jss setup`), or when building in a
|
|
@@ -17,6 +19,8 @@ SITECORE_API_HOST=
|
|
|
17
19
|
# the resolved Sitecore API hostname + the `graphQLEndpointPath` defined in your `package.json`.
|
|
18
20
|
GRAPH_QL_ENDPOINT=
|
|
19
21
|
|
|
22
|
+
# ==============================================
|
|
23
|
+
|
|
20
24
|
# Your Sitecore site name.
|
|
21
25
|
# Uses your `package.json` config `appName` if empty.
|
|
22
26
|
SITECORE_SITE_NAME=
|
|
@@ -81,7 +81,6 @@
|
|
|
81
81
|
"@sitecore-jss/sitecore-jss-angular-schematics": "~22.2.0-canary",
|
|
82
82
|
"@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
|
|
83
83
|
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
|
|
84
|
-
"@types/isomorphic-fetch": "0.0.35",
|
|
85
84
|
"@types/jasmine": "~3.6.7",
|
|
86
85
|
"@types/jasminewd2": "~2.0.8",
|
|
87
86
|
"@types/node": "~20.14.10",
|
|
@@ -99,7 +98,6 @@
|
|
|
99
98
|
"eslint-plugin-import": "2.29.1",
|
|
100
99
|
"eslint-plugin-jsdoc": "48.7.0",
|
|
101
100
|
"eslint-plugin-prefer-arrow": "1.2.3",
|
|
102
|
-
"isomorphic-fetch": "^3.0.0",
|
|
103
101
|
"jasmine-core": "~3.7.1",
|
|
104
102
|
"jasmine-spec-reporter": "~6.0.0",
|
|
105
103
|
"karma": "^6.3.2",
|
|
@@ -12,7 +12,6 @@ class FallbackPlugin implements ConfigPlugin {
|
|
|
12
12
|
async exec(config: JssConfig) {
|
|
13
13
|
return Object.assign({}, config, {
|
|
14
14
|
defaultLanguage: config.defaultLanguage || 'en',
|
|
15
|
-
sitecoreApiKey: config.sitecoreApiKey || 'no-api-key-set',
|
|
16
15
|
<% if (!locals.xmcloud) { -%>
|
|
17
16
|
layoutServiceConfigurationName: config.layoutServiceConfigurationName || 'default',
|
|
18
17
|
<% } -%>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
1
2
|
import * as fs from 'fs';
|
|
2
3
|
import * as path from 'path';
|
|
3
4
|
import { constantCase } from 'constant-case';
|
|
@@ -38,6 +39,14 @@ export function generateConfig(
|
|
|
38
39
|
defaultConfig: JssConfig = defaultConfigValue,
|
|
39
40
|
configOverrides?: { [key: string]: unknown }
|
|
40
41
|
) {
|
|
42
|
+
// Handle undefined values
|
|
43
|
+
defaultConfig = Object.keys(defaultConfig).reduce((acc, key) => {
|
|
44
|
+
return {
|
|
45
|
+
...acc,
|
|
46
|
+
[key]: defaultConfig[key] || '',
|
|
47
|
+
};
|
|
48
|
+
}, {});
|
|
49
|
+
|
|
41
50
|
jssConfigFactory
|
|
42
51
|
.create(defaultConfig)
|
|
43
52
|
.then((config) => {
|
|
@@ -67,9 +76,11 @@ export function writeConfig(config: JssConfig, outputPath?: string) {
|
|
|
67
76
|
|
|
68
77
|
// Set base configuration values, allowing override with environment variables
|
|
69
78
|
Object.keys(config).forEach((prop) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
// Handle undefined values
|
|
80
|
+
const value = config[prop] || '';
|
|
81
|
+
configText += `config.${prop} = process.env.${constantCase(
|
|
82
|
+
prop
|
|
83
|
+
)} || "${value.toString().trim()}";\n`;
|
|
73
84
|
});
|
|
74
85
|
|
|
75
86
|
configText += `module.exports.environment = config;`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import * as fetch from 'isomorphic-fetch';
|
|
2
1
|
import * as fs from 'fs';
|
|
3
2
|
import { generateConfig } from './generate-config';
|
|
3
|
+
import clientFactory from 'lib/graphql-client-factory';
|
|
4
|
+
import { getGraphQLClientFactoryConfig } from 'lib/graphql-client-factory/config';
|
|
4
5
|
|
|
5
6
|
// Apollo Client supports caching GraphQL responses, which can greatly reduce network traffic needs.
|
|
6
7
|
// In order to work correctly with interfaces in GraphQL, it needs to know some basic information about
|
|
@@ -11,26 +12,21 @@ import { generateConfig } from './generate-config';
|
|
|
11
12
|
|
|
12
13
|
generateConfig('src/environments/environment.js');
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
const clientFactoryConfig = getGraphQLClientFactoryConfig();
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
jssConfig = require('../src/environments/environment').environment;
|
|
18
|
-
} catch (e) {
|
|
19
|
-
console.error(
|
|
20
|
-
'Unable to require JSS config. Ensure `jss setup` has been run, and the app has been started at least once after setup.'
|
|
21
|
-
);
|
|
22
|
-
console.error(e);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
17
|
+
console.log(`Updating GraphQL fragment type data from ${clientFactoryConfig.endpoint}...`);
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
clientFactory()
|
|
20
|
+
.request<{
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
__schema: {
|
|
23
|
+
kind: string;
|
|
24
|
+
name: string;
|
|
25
|
+
types: { possibleTypes?: { name: string } }[];
|
|
26
|
+
};
|
|
27
|
+
}>(
|
|
28
|
+
`
|
|
29
|
+
{
|
|
34
30
|
__schema {
|
|
35
31
|
types {
|
|
36
32
|
kind
|
|
@@ -41,22 +37,18 @@ fetch(jssConfig.graphQLEndpoint, {
|
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
.then((result) => result.json())
|
|
40
|
+
`
|
|
41
|
+
)
|
|
48
42
|
.then((result) => {
|
|
49
43
|
// here we're filtering out any type information unrelated to unions or interfaces
|
|
50
|
-
const filteredData = result.
|
|
51
|
-
(type: { possibleTypes: Array<string> }) => type.possibleTypes !== null
|
|
52
|
-
);
|
|
44
|
+
const filteredData = result.__schema.types.filter((type) => type.possibleTypes !== null);
|
|
53
45
|
|
|
54
46
|
const filteredResult = { ...result };
|
|
55
|
-
filteredResult.
|
|
47
|
+
filteredResult.__schema.types = filteredData;
|
|
56
48
|
|
|
57
49
|
fs.writeFile(
|
|
58
50
|
'./src/graphql-fragment-types.ts',
|
|
59
|
-
`export default ${JSON.stringify(filteredResult
|
|
51
|
+
`export default ${JSON.stringify(filteredResult, null, 2)}`,
|
|
60
52
|
(err) => {
|
|
61
53
|
if (err) {
|
|
62
54
|
console.error('Error writing GraphQLFragmentTypes file', err);
|
|
@@ -6,7 +6,8 @@ import 'zone.js';
|
|
|
6
6
|
import { JssRouteBuilderService } from './src/app/routing/jss-route-builder.service';
|
|
7
7
|
import { environment } from './src/environments/environment';
|
|
8
8
|
import { AppServerModule, renderModule } from './src/main.server';
|
|
9
|
-
import
|
|
9
|
+
import clientFactory from './src/app/lib/graphql-client-factory';
|
|
10
|
+
import { getGraphQLClientFactoryConfig } from './src/app/lib/graphql-client-factory/config';
|
|
10
11
|
import { dictionaryServiceFactory } from './src/app/lib/dictionary-service-factory';
|
|
11
12
|
import { layoutServiceFactory } from './src/app/lib/layout-service-factory';
|
|
12
13
|
|
|
@@ -103,8 +104,7 @@ function parseRouteUrl(url: string) {
|
|
|
103
104
|
const apiKey = environment.sitecoreApiKey;
|
|
104
105
|
const siteName = environment.sitecoreSiteName;
|
|
105
106
|
const defaultLanguage = environment.defaultLanguage;
|
|
106
|
-
const
|
|
107
|
-
const graphQLEndpoint = environment.graphQLEndpoint;
|
|
107
|
+
const getClientFactoryConfig = getGraphQLClientFactoryConfig;
|
|
108
108
|
|
|
109
109
|
export {
|
|
110
110
|
renderView,
|
|
@@ -113,9 +113,8 @@ export {
|
|
|
113
113
|
apiKey,
|
|
114
114
|
siteName,
|
|
115
115
|
clientFactory,
|
|
116
|
+
getClientFactoryConfig,
|
|
116
117
|
dictionaryServiceFactory,
|
|
117
118
|
layoutServiceFactory,
|
|
118
119
|
defaultLanguage,
|
|
119
|
-
graphQLEndpointPath,
|
|
120
|
-
graphQLEndpoint,
|
|
121
120
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { RouteData, LayoutServiceContextData } from '@sitecore-jss/sitecore-jss-angular';
|
|
2
2
|
import { LayoutServiceError } from './layout/jss-layout.service';
|
|
3
3
|
|
|
4
|
-
export class JssState
|
|
4
|
+
export class JssState {
|
|
5
5
|
language: string;
|
|
6
6
|
serverRoute: string;
|
|
7
7
|
routeFetchError?: LayoutServiceError;
|
|
8
8
|
sitecore?: LayoutServiceContextData & {
|
|
9
|
-
route: RouteData
|
|
9
|
+
route: RouteData | null;
|
|
10
10
|
};
|
|
11
11
|
viewBag: { [key: string]: unknown };
|
|
12
12
|
}
|
|
@@ -11,6 +11,7 @@ import { JssTranslationClientLoaderService } from './i18n/jss-translation-client
|
|
|
11
11
|
import { JssTranslationLoaderService } from './i18n/jss-translation-loader.service';
|
|
12
12
|
import { GraphQLModule } from './jss-graphql.module';
|
|
13
13
|
import { JssMetaService } from './jss-meta.service';
|
|
14
|
+
import { JssLinkService } from './jss-link.service';
|
|
14
15
|
|
|
15
16
|
@NgModule({
|
|
16
17
|
imports: [
|
|
@@ -32,6 +33,7 @@ import { JssMetaService } from './jss-meta.service';
|
|
|
32
33
|
JssContextService,
|
|
33
34
|
JssLayoutService,
|
|
34
35
|
JssMetaService,
|
|
36
|
+
JssLinkService,
|
|
35
37
|
// IMPORTANT: you must set the base href with this token, not a <base> tag in the HTML.
|
|
36
38
|
// the Sitecore Experience Editor will not work correctly when a base tag is used.
|
|
37
39
|
{ provide: APP_BASE_HREF, useValue: '/' },
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
<% } -%>
|
|
8
8
|
} from '@sitecore-jss/sitecore-jss-angular';
|
|
9
9
|
import { environment as env } from '../../environments/environment';
|
|
10
|
-
import
|
|
10
|
+
import clientFactory from './graphql-client-factory';
|
|
11
11
|
|
|
12
12
|
export class DictionaryServiceFactory {
|
|
13
13
|
create(): DictionaryService {
|
|
@@ -24,6 +24,9 @@ export class DictionaryServiceFactory {
|
|
|
24
24
|
new GraphQLDictionaryService({
|
|
25
25
|
clientFactory,
|
|
26
26
|
siteName: env.sitecoreSiteName,
|
|
27
|
+
<% if (locals.xmcloud) { -%>
|
|
28
|
+
useSiteQuery: true,
|
|
29
|
+
<% } -%>
|
|
27
30
|
/*
|
|
28
31
|
The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current
|
|
29
32
|
app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GraphQLRequestClientFactoryConfig } from '@sitecore-jss/sitecore-jss-angular/cjs';
|
|
2
|
+
import { environment as env } from '../../../environments/environment';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gets the configuration for the GraphQLRequestClientFactory
|
|
6
|
+
* @returns GraphQLRequestClientFactoryConfig
|
|
7
|
+
*/
|
|
8
|
+
export const getGraphQLClientFactoryConfig = () => {
|
|
9
|
+
let clientConfig: GraphQLRequestClientFactoryConfig;
|
|
10
|
+
|
|
11
|
+
if (env.graphQLEndpoint && env.sitecoreApiKey) {
|
|
12
|
+
clientConfig = {
|
|
13
|
+
endpoint: env.graphQLEndpoint,
|
|
14
|
+
apiKey: env.sitecoreApiKey,
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error('Please configure your graphQLEndpoint and sitecoreApiKey.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return clientConfig;
|
|
21
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss-angular/cjs';
|
|
2
|
+
import { getGraphQLClientFactoryConfig } from './config';
|
|
3
|
+
|
|
4
|
+
// The GraphQLRequestClientFactory serves as the central hub for executing GraphQL requests within the application
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new GraphQLRequestClientFactory instance
|
|
8
|
+
* @returns GraphQLRequestClientFactory instance
|
|
9
|
+
*/
|
|
10
|
+
const createGraphQLClientFactory = () => {
|
|
11
|
+
const clientConfig = getGraphQLClientFactoryConfig();
|
|
12
|
+
|
|
13
|
+
return GraphQLRequestClient.createClientFactory(clientConfig);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default createGraphQLClientFactory();
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
<% } -%>
|
|
8
8
|
} from '@sitecore-jss/sitecore-jss-angular';
|
|
9
9
|
import { environment } from '../../environments/environment';
|
|
10
|
-
import
|
|
10
|
+
import clientFactory from './graphql-client-factory';
|
|
11
11
|
|
|
12
12
|
export class LayoutServiceFactory {
|
|
13
13
|
create(): LayoutService {
|
|
@@ -9,12 +9,12 @@ import { JssMetaService } from '../../jss-meta.service';
|
|
|
9
9
|
enum LayoutState {
|
|
10
10
|
Layout,
|
|
11
11
|
NotFound,
|
|
12
|
-
Error
|
|
12
|
+
Error,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
interface RouteFields {
|
|
16
16
|
[name: string]: unknown;
|
|
17
|
-
pageTitle
|
|
17
|
+
pageTitle?: Field<string>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
@Component({
|
|
@@ -28,14 +28,11 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|
|
28
28
|
subscription: Subscription;
|
|
29
29
|
errorContextData: LayoutServiceContextData;
|
|
30
30
|
|
|
31
|
-
constructor(
|
|
32
|
-
private activatedRoute: ActivatedRoute,
|
|
33
|
-
private readonly meta: JssMetaService,
|
|
34
|
-
) { }
|
|
31
|
+
constructor(private activatedRoute: ActivatedRoute, private readonly meta: JssMetaService) {}
|
|
35
32
|
|
|
36
33
|
ngOnInit() {
|
|
37
34
|
// route data is populated by the JssRouteResolver
|
|
38
|
-
this.subscription = this.activatedRoute.data.subscribe((data: { jssState: JssState
|
|
35
|
+
this.subscription = this.activatedRoute.data.subscribe((data: { jssState: JssState }) => {
|
|
39
36
|
if (!data.jssState) {
|
|
40
37
|
this.state = LayoutState.NotFound;
|
|
41
38
|
return;
|
|
@@ -48,13 +45,17 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
if (data.jssState.routeFetchError) {
|
|
51
|
-
if (
|
|
48
|
+
if (
|
|
49
|
+
data.jssState.routeFetchError.status >= 400 &&
|
|
50
|
+
data.jssState.routeFetchError.status < 500
|
|
51
|
+
) {
|
|
52
52
|
this.state = LayoutState.NotFound;
|
|
53
53
|
} else {
|
|
54
54
|
this.state = LayoutState.Error;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
this.errorContextData =
|
|
57
|
+
this.errorContextData =
|
|
58
|
+
data.jssState.routeFetchError.data && data.jssState.routeFetchError.data.sitecore;
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
61
|
}
|
|
@@ -8,7 +8,7 @@ const chalk = require('chalk');
|
|
|
8
8
|
*/
|
|
9
9
|
class DisconnectedPlugin implements ConfigPlugin {
|
|
10
10
|
// should come before other plugins
|
|
11
|
-
order =
|
|
11
|
+
order = 2;
|
|
12
12
|
|
|
13
13
|
async exec(config: JssConfig) {
|
|
14
14
|
const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
|
|
@@ -20,7 +20,9 @@ class DisconnectedPlugin implements ConfigPlugin {
|
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
return config
|
|
23
|
+
return Object.assign({}, config, {
|
|
24
|
+
sitecoreApiKey: config.sitecoreApiKey || 'no-api-key-set',
|
|
25
|
+
});
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
|
|
2
|
+
# ========== Sitecore Edge Platform ===========
|
|
3
|
+
|
|
4
|
+
# Your unified Sitecore Edge Context Id.
|
|
5
|
+
# This will be used over any Sitecore Preview / Delivery Edge variables (above).
|
|
6
|
+
SITECORE_EDGE_CONTEXT_ID=
|
|
7
|
+
|
|
2
8
|
# ========== XM Cloud Proxy ===========
|
|
3
9
|
|
|
4
10
|
# Your XM Cloud Proxy hostname is needed to build the app and execute the client-side requests against the proxy server.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JssConfig } from 'lib/config';
|
|
2
2
|
import { ConfigPlugin } from '..';
|
|
3
3
|
import { constantCase } from 'constant-case';
|
|
4
|
+
import chalk from 'chalk';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* This plugin will set XM Cloud related config props.
|
|
@@ -13,9 +14,24 @@ class XMCloudPlugin implements ConfigPlugin {
|
|
|
13
14
|
const proxyBuildPath = process.env[`${constantCase('proxyBuildPath')}`]?.replace(/\/$/, '');
|
|
14
15
|
const proxyHost = process.env[`${constantCase('proxyHost')}`];
|
|
15
16
|
|
|
17
|
+
const sitecoreEdgeUrl =
|
|
18
|
+
process.env[`${constantCase('sitecoreEdgeUrl')}`]?.replace(/\/$/, '') ||
|
|
19
|
+
'https://edge-platform.sitecorecloud.io';
|
|
20
|
+
const sitecoreEdgeContextId = process.env[`${constantCase('sitecoreEdgeContextId')}`];
|
|
21
|
+
|
|
22
|
+
if (config.sitecoreApiKey && sitecoreEdgeContextId) {
|
|
23
|
+
console.log(
|
|
24
|
+
chalk.yellow(
|
|
25
|
+
"You have configured both 'sitecoreApiKey' and 'sitecoreEdgeContextId' values. The 'sitecoreEdgeContextId' is used instead."
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
16
30
|
return Object.assign({}, config, {
|
|
17
31
|
proxyBuildPath,
|
|
18
32
|
proxyHost,
|
|
33
|
+
sitecoreEdgeUrl,
|
|
34
|
+
sitecoreEdgeContextId,
|
|
19
35
|
});
|
|
20
36
|
}
|
|
21
37
|
}
|
|
@@ -4,11 +4,7 @@ import { HTMLLink } from '@sitecore-jss/sitecore-jss-angular';
|
|
|
4
4
|
|
|
5
5
|
@Injectable()
|
|
6
6
|
export class JssLinkService {
|
|
7
|
-
document: Document
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
this.document = Inject(DOCUMENT);
|
|
11
|
-
}
|
|
7
|
+
constructor(@Inject(DOCUMENT) private document: Document) {}
|
|
12
8
|
|
|
13
9
|
/**
|
|
14
10
|
* Adds link element in the document head.
|
|
@@ -19,6 +15,11 @@ export class JssLinkService {
|
|
|
19
15
|
return;
|
|
20
16
|
}
|
|
21
17
|
|
|
18
|
+
// Check if a link with the same rel and href already exists
|
|
19
|
+
if (this.isDuplicateLink(headLink)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
22
23
|
this.createLink(headLink);
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -39,13 +40,14 @@ export class JssLinkService {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param
|
|
43
|
+
* Checks for an existing link element with the same rel and href attributes.
|
|
44
|
+
* @param headLink - An HTMLLink object to be checked.
|
|
45
|
+
* @returns {boolean} - True if a matching link exists, false otherwise.
|
|
44
46
|
*/
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
private isDuplicateLink(headLink: HTMLLink): boolean {
|
|
48
|
+
const existingLink = this.document.head.querySelector(
|
|
49
|
+
`link[rel='${headLink.rel}'][href='${headLink.href}']`
|
|
50
|
+
);
|
|
51
|
+
return !!existingLink;
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GraphQLRequestClientFactoryConfig,
|
|
3
|
+
getEdgeProxyContentUrl,
|
|
4
|
+
} from '@sitecore-jss/sitecore-jss-angular/cjs';
|
|
5
|
+
import { environment as env } from '../../../environments/environment';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gets the configuration for the GraphQLRequestClientFactory
|
|
9
|
+
* @returns GraphQLRequestClientFactoryConfig
|
|
10
|
+
*/
|
|
11
|
+
export const getGraphQLClientFactoryConfig = () => {
|
|
12
|
+
let clientConfig: GraphQLRequestClientFactoryConfig;
|
|
13
|
+
|
|
14
|
+
// Server side requests should go directly to the Sitecore, browser requests should go through the proxy.
|
|
15
|
+
const isServer = typeof window === 'undefined';
|
|
16
|
+
// If we are in a production environment we are going to use Node XM Cloud proxy
|
|
17
|
+
const isProduction = env.production === 'true';
|
|
18
|
+
|
|
19
|
+
if (isProduction) {
|
|
20
|
+
if (!env.proxyHost) {
|
|
21
|
+
throw new Error('Please configure your proxyHost.');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (env.sitecoreEdgeContextId) {
|
|
25
|
+
clientConfig = {
|
|
26
|
+
endpoint: isServer
|
|
27
|
+
? getEdgeProxyContentUrl(env.sitecoreEdgeContextId, env.sitecoreEdgeUrl)
|
|
28
|
+
: getEdgeProxyContentUrl(env.sitecoreEdgeContextId, env.proxyHost),
|
|
29
|
+
};
|
|
30
|
+
} else if (env.graphQLEndpoint && env.sitecoreApiKey) {
|
|
31
|
+
const graphQLEndpointPath = new URL(env.graphQLEndpoint).pathname;
|
|
32
|
+
|
|
33
|
+
clientConfig = {
|
|
34
|
+
endpoint: isServer ? env.graphQLEndpoint : `${env.proxyHost}${graphQLEndpointPath}`,
|
|
35
|
+
apiKey: env.sitecoreApiKey,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
if (env.sitecoreEdgeContextId) {
|
|
40
|
+
clientConfig = {
|
|
41
|
+
endpoint: getEdgeProxyContentUrl(env.sitecoreEdgeContextId, env.sitecoreEdgeUrl),
|
|
42
|
+
};
|
|
43
|
+
} else if (env.graphQLEndpoint && env.sitecoreApiKey) {
|
|
44
|
+
clientConfig = {
|
|
45
|
+
endpoint: env.graphQLEndpoint,
|
|
46
|
+
apiKey: env.sitecoreApiKey,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!clientConfig.endpoint) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'Please configure either your sitecoreEdgeContextId, or your graphQLEndpoint and sitecoreApiKey.'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return clientConfig;
|
|
58
|
+
};
|
|
@@ -11,6 +11,7 @@ import { Subscription } from 'rxjs';
|
|
|
11
11
|
import { JssState } from '../../JssState';
|
|
12
12
|
import { JssMetaService } from '../../jss-meta.service';
|
|
13
13
|
import { JssLinkService } from '../../jss-link.service';
|
|
14
|
+
import { environment as env } from '../../../environments/environment';
|
|
14
15
|
|
|
15
16
|
enum LayoutState {
|
|
16
17
|
Layout,
|
|
@@ -20,7 +21,7 @@ enum LayoutState {
|
|
|
20
21
|
|
|
21
22
|
interface RouteFields {
|
|
22
23
|
[name: string]: unknown;
|
|
23
|
-
pageTitle
|
|
24
|
+
pageTitle?: Field<string>;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
@Component({
|
|
@@ -43,53 +44,45 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|
|
43
44
|
|
|
44
45
|
ngOnInit() {
|
|
45
46
|
// route data is populated by the JssRouteResolver
|
|
46
|
-
this.subscription = this.activatedRoute.data.subscribe(
|
|
47
|
-
(data
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (data.jssState.sitecore && data.jssState.sitecore.route) {
|
|
54
|
-
this.route = data.jssState.sitecore.route;
|
|
55
|
-
this.setMetadata(this.route.fields);
|
|
56
|
-
this.state = LayoutState.Layout;
|
|
57
|
-
this.mainClassPageEditing = data.jssState.sitecore.context.pageEditing
|
|
58
|
-
? 'editing-mode'
|
|
59
|
-
: 'prod-mode';
|
|
47
|
+
this.subscription = this.activatedRoute.data.subscribe((data: { jssState: JssState }) => {
|
|
48
|
+
if (!data.jssState) {
|
|
49
|
+
this.state = LayoutState.NotFound;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
53
|
+
if (data.jssState.sitecore && data.jssState.sitecore.route) {
|
|
54
|
+
this.route = data.jssState.sitecore.route;
|
|
55
|
+
this.setMetadata(this.route.fields);
|
|
56
|
+
this.state = LayoutState.Layout;
|
|
57
|
+
this.mainClassPageEditing = data.jssState.sitecore.context.pageEditing
|
|
58
|
+
? 'editing-mode'
|
|
59
|
+
: 'prod-mode';
|
|
69
60
|
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
const contentStyles = getContentStylesheetLink(
|
|
62
|
+
{ sitecore: data.jssState.sitecore },
|
|
63
|
+
env.sitecoreEdgeContextId,
|
|
64
|
+
env.sitecoreEdgeUrl
|
|
65
|
+
);
|
|
72
66
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
67
|
+
if (contentStyles) {
|
|
68
|
+
this.linkService.addHeadLinks(contentStyles);
|
|
76
69
|
}
|
|
70
|
+
}
|
|
77
71
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.errorContextData =
|
|
89
|
-
data.jssState.routeFetchError.data && data.jssState.routeFetchError.data.sitecore;
|
|
72
|
+
if (data.jssState.routeFetchError) {
|
|
73
|
+
if (
|
|
74
|
+
data.jssState.routeFetchError.status >= 400 &&
|
|
75
|
+
data.jssState.routeFetchError.status < 500
|
|
76
|
+
) {
|
|
77
|
+
this.state = LayoutState.NotFound;
|
|
78
|
+
} else {
|
|
79
|
+
this.state = LayoutState.Error;
|
|
90
80
|
}
|
|
81
|
+
|
|
82
|
+
this.errorContextData =
|
|
83
|
+
data.jssState.routeFetchError.data && data.jssState.routeFetchError.data.sitecore;
|
|
91
84
|
}
|
|
92
|
-
);
|
|
85
|
+
});
|
|
93
86
|
}
|
|
94
87
|
|
|
95
88
|
ngOnDestroy() {
|
|
@@ -104,7 +97,7 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|
|
104
97
|
}
|
|
105
98
|
}
|
|
106
99
|
|
|
107
|
-
|
|
100
|
+
onPlaceholderLoaded(_placeholderName: string) {
|
|
108
101
|
// you may optionally hook to the loaded event for a placeholder,
|
|
109
102
|
// which can be useful for analytics and other DOM-based things that need to know when a placeholder's content is available.
|
|
110
103
|
}
|
|
@@ -13,7 +13,6 @@ class FallbackPlugin implements ConfigPlugin {
|
|
|
13
13
|
async exec(config: JssConfig) {
|
|
14
14
|
return Object.assign({}, config, {
|
|
15
15
|
defaultLanguage: config.defaultLanguage || 'en',
|
|
16
|
-
sitecoreApiKey: config.sitecoreApiKey || 'no-api-key-set',
|
|
17
16
|
layoutServiceConfigurationName: config.layoutServiceConfigurationName || 'default',
|
|
18
17
|
publicUrl: config.publicUrl || getPublicUrl(),
|
|
19
18
|
});
|
|
@@ -29,6 +29,11 @@ generateConfig(defaultConfig);
|
|
|
29
29
|
* @param {JssConfig} defaultConfig Default configuration.
|
|
30
30
|
*/
|
|
31
31
|
function generateConfig(defaultConfig: JssConfig): void {
|
|
32
|
+
// Handle undefined values
|
|
33
|
+
Object.keys(defaultConfig).forEach(prop => {
|
|
34
|
+
defaultConfig[prop] = defaultConfig[prop] || '';
|
|
35
|
+
}, {});
|
|
36
|
+
|
|
32
37
|
jssConfigFactory
|
|
33
38
|
.create(defaultConfig)
|
|
34
39
|
.then(config => {
|
|
@@ -53,7 +58,9 @@ const config = {};\n`;
|
|
|
53
58
|
|
|
54
59
|
// Set configuration values, allowing override with environment variables
|
|
55
60
|
Object.keys(config).forEach(prop => {
|
|
56
|
-
|
|
61
|
+
// Handle undefined values
|
|
62
|
+
const value = config[prop] || '';
|
|
63
|
+
configText += `config.${prop} = process.env.${constantCase(prop)} || '${value.trim()}';\n`;
|
|
57
64
|
});
|
|
58
65
|
|
|
59
66
|
configText += `module.exports = config;`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-xmcloud-sample",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.2.0-canary",
|
|
4
4
|
"description": "Node XM Cloud Proxy sample for running XM Cloud JSS SPA apps",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Sitecore Corporation",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"http-proxy-middleware": "^3.0.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@sitecore-jss/sitecore-jss": "~22.
|
|
19
|
+
"@sitecore-jss/sitecore-jss": "~22.2.0-canary",
|
|
20
20
|
"@types/compression": "^1.7.2",
|
|
21
21
|
"@types/express": "^4.17.17",
|
|
22
22
|
"ts-node": "^10.9.1",
|
|
@@ -3,7 +3,7 @@ import { Config, ServerBundle } from './types';
|
|
|
3
3
|
/**
|
|
4
4
|
* The server.bundle.js file from your pre-built SPA app.
|
|
5
5
|
*/
|
|
6
|
-
const bundlePath = process.env.PROXY_BUNDLE_PATH ||
|
|
6
|
+
const bundlePath = process.env.PROXY_BUNDLE_PATH || '../dist/server.bundle';
|
|
7
7
|
|
|
8
8
|
const serverBundle: ServerBundle = require(bundlePath);
|
|
9
9
|
|
|
@@ -21,12 +21,11 @@ const requiredProperties = [
|
|
|
21
21
|
'renderView',
|
|
22
22
|
'parseRouteUrl',
|
|
23
23
|
'clientFactory',
|
|
24
|
+
'getClientFactoryConfig',
|
|
24
25
|
'siteName',
|
|
25
26
|
'defaultLanguage',
|
|
26
27
|
'layoutServiceFactory',
|
|
27
28
|
'dictionaryServiceFactory',
|
|
28
|
-
'graphQLEndpointPath',
|
|
29
|
-
'graphQLEndpoint',
|
|
30
29
|
];
|
|
31
30
|
|
|
32
31
|
const missingProperties = requiredProperties.filter((property) => !config.serverBundle[property]);
|
|
@@ -39,6 +38,31 @@ if (missingProperties.length > 0) {
|
|
|
39
38
|
);
|
|
40
39
|
}
|
|
41
40
|
|
|
41
|
+
/**
|
|
42
|
+
* GraphQL endpoint resolution to meet the requirements of the http-proxy-middleware
|
|
43
|
+
*/
|
|
44
|
+
const graphQLEndpoint = (() => {
|
|
45
|
+
const clientFactoryConfig = config.serverBundle.getClientFactoryConfig();
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const graphQLEndpoint = new URL(clientFactoryConfig.endpoint);
|
|
49
|
+
// Browser request path to the proxy. Includes only the pathname.
|
|
50
|
+
const pathname = graphQLEndpoint.pathname;
|
|
51
|
+
// Target URL for the proxy. Can't include the query string.
|
|
52
|
+
const target = `${graphQLEndpoint.protocol}//${graphQLEndpoint.hostname}${pathname}`;
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
target,
|
|
56
|
+
path: pathname,
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`ERROR: The serverBundle should export a getClientFactoryConfig function with valid GraphQL endpoint URL returned, current value is ${clientFactoryConfig.endpoint}. ` +
|
|
61
|
+
'Please check your server bundle.'
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
|
|
42
66
|
const layoutService = layoutServiceFactory.create();
|
|
43
67
|
|
|
44
68
|
const dictionaryService = dictionaryServiceFactory.create();
|
|
@@ -94,9 +118,9 @@ server.use(
|
|
|
94
118
|
* Proxy browser GraphQL requests to the Sitecore GraphQL endpoint
|
|
95
119
|
*/
|
|
96
120
|
server.use(
|
|
97
|
-
|
|
121
|
+
graphQLEndpoint.path,
|
|
98
122
|
createProxyMiddleware({
|
|
99
|
-
target:
|
|
123
|
+
target: graphQLEndpoint.target,
|
|
100
124
|
changeOrigin: true,
|
|
101
125
|
})
|
|
102
126
|
);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
GraphQLRequestClientFactory,
|
|
3
|
+
GraphQLRequestClientFactoryConfig,
|
|
4
|
+
} from '@sitecore-jss/sitecore-jss';
|
|
2
5
|
import { DictionaryService } from '@sitecore-jss/sitecore-jss/i18n';
|
|
3
6
|
import { LayoutService, LayoutServiceData } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
7
|
|
|
@@ -44,12 +47,11 @@ export interface ServerBundle {
|
|
|
44
47
|
renderView: AppRenderer;
|
|
45
48
|
parseRouteUrl: RouteUrlParser;
|
|
46
49
|
clientFactory: GraphQLRequestClientFactory;
|
|
50
|
+
getClientFactoryConfig: () => GraphQLRequestClientFactoryConfig;
|
|
47
51
|
siteName: string;
|
|
48
52
|
defaultLanguage: string;
|
|
49
53
|
layoutServiceFactory: { create: () => LayoutService };
|
|
50
54
|
dictionaryServiceFactory: { create: () => DictionaryService };
|
|
51
|
-
graphQLEndpointPath: string;
|
|
52
|
-
graphQLEndpoint: string;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export interface Config {
|
|
@@ -31,6 +31,11 @@ generateConfig();
|
|
|
31
31
|
* NOTE! Any configs returned here will be written into the client-side JS bundle. DO NOT PUT SECRETS HERE.
|
|
32
32
|
*/
|
|
33
33
|
function generateConfig() {
|
|
34
|
+
// Handle undefined values
|
|
35
|
+
Object.keys(defaultConfig).forEach((prop) => {
|
|
36
|
+
defaultConfig[prop] = defaultConfig[prop] || '';
|
|
37
|
+
});
|
|
38
|
+
|
|
34
39
|
try {
|
|
35
40
|
config = jssConfigFactory.create(defaultConfig);
|
|
36
41
|
} catch (error) {
|
|
@@ -50,9 +55,11 @@ const config = {};\n`;
|
|
|
50
55
|
|
|
51
56
|
// Set base configuration values, allowing override with environment variables
|
|
52
57
|
Object.keys(config).forEach(prop => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
58
|
+
// Handle undefined values
|
|
59
|
+
const value = config[prop] || '';
|
|
60
|
+
configText += `config.${prop} = process.env.REACT_APP_${constantCase(
|
|
61
|
+
prop
|
|
62
|
+
)} || "${value.trim()}";\n`;
|
|
56
63
|
});
|
|
57
64
|
configText += 'module.exports = config;';
|
|
58
65
|
|
|
@@ -33,6 +33,11 @@ module.exports = function generateConfig(configOverrides) {
|
|
|
33
33
|
// and finally config passed in the configOverrides param wins.
|
|
34
34
|
const config = Object.assign(defaultConfig, scjssConfig, packageJson, configOverrides);
|
|
35
35
|
|
|
36
|
+
// Handle undefined values
|
|
37
|
+
Object.keys(config).forEach((prop) => {
|
|
38
|
+
config[prop] = config[prop] || '';
|
|
39
|
+
});
|
|
40
|
+
|
|
36
41
|
// The GraphQL endpoint is an example of making a _computed_ config setting
|
|
37
42
|
// based on other config settings.
|
|
38
43
|
const computedConfig = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sitecore-jss",
|
|
3
|
-
"version": "22.2.0-canary.
|
|
3
|
+
"version": "22.2.0-canary.12",
|
|
4
4
|
"description": "Sitecore JSS initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"ts-node": "^10.9.1",
|
|
64
64
|
"typescript": "~4.9.5"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "64712384661c6bf2379a610df10c259cd709299e"
|
|
67
67
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GraphQLRequestClientFactoryConfig,
|
|
3
|
-
GraphQLRequestClient,
|
|
4
|
-
} from '@sitecore-jss/sitecore-jss-angular';
|
|
5
|
-
import { environment as env } from '../../environments/environment';
|
|
6
|
-
|
|
7
|
-
// The GraphQLRequestClientFactory serves as the central hub for executing GraphQL requests within the application
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new GraphQLRequestClientFactory instance
|
|
11
|
-
* @returns GraphQLRequestClientFactory instance
|
|
12
|
-
*/
|
|
13
|
-
export const createGraphQLClientFactory = () => {
|
|
14
|
-
let clientConfig: GraphQLRequestClientFactoryConfig;
|
|
15
|
-
|
|
16
|
-
if (env.graphQLEndpoint && env.sitecoreApiKey) {
|
|
17
|
-
clientConfig = {
|
|
18
|
-
endpoint: env.graphQLEndpoint,
|
|
19
|
-
apiKey: env.sitecoreApiKey,
|
|
20
|
-
};
|
|
21
|
-
} else {
|
|
22
|
-
throw new Error('Please configure your graphQLEndpoint and sitecoreApiKey.');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return GraphQLRequestClient.createClientFactory(clientConfig);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const clientFactory = createGraphQLClientFactory();
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GraphQLRequestClientFactoryConfig,
|
|
3
|
-
GraphQLRequestClient,
|
|
4
|
-
} from '@sitecore-jss/sitecore-jss-angular';
|
|
5
|
-
import { environment as env } from '../../environments/environment';
|
|
6
|
-
|
|
7
|
-
// The GraphQLRequestClientFactory serves as the central hub for executing GraphQL requests within the application
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new GraphQLRequestClientFactory instance
|
|
11
|
-
* @returns GraphQLRequestClientFactory instance
|
|
12
|
-
*/
|
|
13
|
-
export const createGraphQLClientFactory = () => {
|
|
14
|
-
let clientConfig: GraphQLRequestClientFactoryConfig;
|
|
15
|
-
|
|
16
|
-
// If we are in a production environment we are going to use Node XM Cloud proxy
|
|
17
|
-
if (env.production === 'true') {
|
|
18
|
-
if (env.proxyHost && env.sitecoreApiKey && env.graphQLEndpoint) {
|
|
19
|
-
// Server side requests should go directly to the Sitecore, browser requests should go through the proxy.
|
|
20
|
-
clientConfig = {
|
|
21
|
-
endpoint:
|
|
22
|
-
typeof window === 'undefined'
|
|
23
|
-
? env.graphQLEndpoint
|
|
24
|
-
: `${env.proxyHost}${env.graphQLEndpointPath}`,
|
|
25
|
-
apiKey: env.sitecoreApiKey,
|
|
26
|
-
};
|
|
27
|
-
} else {
|
|
28
|
-
throw new Error('Please configure your proxyHost, sitecoreApiKey, graphQLEndpoint.');
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
if (env.graphQLEndpoint && env.sitecoreApiKey) {
|
|
32
|
-
clientConfig = {
|
|
33
|
-
endpoint: env.graphQLEndpoint,
|
|
34
|
-
apiKey: env.sitecoreApiKey,
|
|
35
|
-
};
|
|
36
|
-
} else {
|
|
37
|
-
throw new Error('Please configure your graphQLEndpoint and sitecoreApiKey.');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return GraphQLRequestClient.createClientFactory(clientConfig);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const clientFactory = createGraphQLClientFactory();
|