Skip to content

Commit

Permalink
Rename jssAppName to siteName variables in proxy apps templates
Browse files Browse the repository at this point in the history
  • Loading branch information
yavorsk committed Oct 31, 2023
1 parent 7f88937 commit 3342202
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SITECORE_JSS_APP_NAME=
SITECORE_SITE_NAME=
SITECORE_JSS_SERVER_BUNDLE=
SITECORE_EXPERIENCE_EDGE_ENDPOINT=
SITECORE_API_KEY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ Open `config.js` and specify your application bundle and connection settings.

The following environment variables can be set to configure the SSR 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).

| Parameter | Description |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SITECORE_JSS_APP_NAME` | The JSS app's name. Used when request layout data and dictionary using graphql query and the default value of `SITECORE_JSS_SERVER_BUNDLE` if it's not set. |
| `SITECORE_API_KEY` | The API key provisioned on Sitecore Experience Edge. |
| `SITECORE_JSS_SERVER_BUNDLE` | Path to the JSS app's `server.bundle.js` file. |
| `SITECORE_EXPERIENCE_EDGE_ENDPOINT` | Sitecore Experience Edge endpoint. |
| `DEFAULT_LANGUAGE` | The JSS app's default language. Used to determine language context in case language is not specified in request URL. |
| `PORT` | Optional. Port which will be used when start sample. Default can be seen in [config.js](./config.js). |
| Parameter | Description |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SITECORE_SITE_NAME` | The sitecore site's name. Used when request layout data and dictionary using graphql query and the default value of `SITECORE_JSS_SERVER_BUNDLE` if it's not set. |
| `SITECORE_API_KEY` | The API key provisioned on Sitecore Experience Edge. |
| `SITECORE_JSS_SERVER_BUNDLE` | Path to the JSS app's `server.bundle.js` file. |
| `SITECORE_EXPERIENCE_EDGE_ENDPOINT` | Sitecore Experience Edge endpoint. |
| `DEFAULT_LANGUAGE` | The JSS app's default language. Used to determine language context in case language is not specified in request URL. |
| `PORT` | Optional. Port which will be used when start sample. Default can be seen in [config.js](./config.js). |

## Build & run

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Config, ServerBundle } from './types';
const appName = process.env.SITECORE_JSS_APP_NAME;
const siteName = process.env.SITECORE_SITE_NAME;

/**
* The server.bundle.js file from your pre-built JSS app
*/

const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${appName}/server.bundle`;
const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${siteName}/server.bundle`;

const serverBundle: ServerBundle = require(bundlePath);

Expand All @@ -29,7 +29,7 @@ export const config: Config = {
* The JSS application name defaults to providing part of the bundle path.
* If not passed as an environment variable or set here, any application name exported from the bundle will be used instead.
*/
appName: appName || serverBundle.appName,
siteName: siteName || serverBundle.siteName,
/**
* Port which will be used when start sample
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const server = express();
const layoutService = new GraphQLLayoutService({
endpoint: config.endpoint,
apiKey: config.apiKey,
siteName: config.appName,
siteName: config.siteName,
});

const dictionaryService = new GraphQLDictionaryService({
endpoint: config.endpoint,
apiKey: config.apiKey,
siteName: config.appName,
siteName: config.siteName,
/*
The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current
app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ declare type RouteUrlParser = (
export interface ServerBundle {
renderView: AppRenderer;
parseRouteUrl: RouteUrlParser;
appName: string;
siteName: string;
apiKey?: string;
}

export interface Config {
[key: string]: unknown;
endpoint: string;
apiKey: string;
appName: string;
siteName: string;
port: string | number;
defaultLanguage: string;
serverBundle: ServerBundle;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SITECORE_JSS_APP_NAME=
SITECORE_SITE_NAME=
SITECORE_JSS_SERVER_BUNDLE=
SITECORE_API_HOST=
SITECORE_API_KEY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import { RestDictionaryService } from '@sitecore-jss/sitecore-jss/i18n';
import { httpAgentsConfig } from './httpAgents';

/**
* The JSS application name defaults to providing part of the bundle path as well as the dictionary service endpoint.
* The sitecore site name defaults to providing part of the bundle path as well as the dictionary service endpoint.
* If not passed as an environment variable or set here, any application name exported from the bundle will be used instead.
*/
let appName = process.env.SITECORE_JSS_APP_NAME || 'YOUR APP NAME';
let siteName = process.env.SITECORE_SITE_NAME || 'YOUR SITE NAME';

/**
* The server.bundle.js file from your pre-built JSS app
*/

const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${appName}/server.bundle`;
const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${siteName}/server.bundle`;

const serverBundle = require(bundlePath) as ServerBundle;

httpAgentsConfig.setUpDefaultAgents(serverBundle);

const apiHost = process.env.SITECORE_API_HOST || 'http://my.sitecore.host';

appName = appName || serverBundle.appName;
siteName = siteName || serverBundle.siteName;

const apiKey = process.env.SITECORE_API_KEY || serverBundle.apiKey || '{YOUR API KEY HERE}';

const dictionaryService = new RestDictionaryService({
apiHost,
siteName: appName,
siteName: siteName,
apiKey,
cacheTimeout: 60,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const setUpDefaultAgents = (httpAgent, httpsAgent) => {

// Export app configuration; this will be used when this app runs in Headless mode (ie node-headless-ssr-experience-edge or node-headless-ssr-proxy)
export const apiKey = config.sitecoreApiKey;
export const appName = config.siteName;
export const siteName = config.siteName;
export const defaultLanguage = config.defaultLanguage;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const setUpDefaultAgents = (httpAgent, httpsAgent) => {
export const apiKey = config.sitecoreApiKey;

/** Export the app name. This will be used by default in Headless mode, removing the need to manually configure the app name on the proxy. */
export const appName = config.siteName;
export const siteName = config.siteName;

/**
* Main entry point to the application when run via Server-Side Rendering,
Expand Down
2 changes: 1 addition & 1 deletion packages/sitecore-jss-proxy/src/ProxyConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface LayoutServiceData {
/** Interface for the server.bundle.js file */
export interface ServerBundle {
[key: string]: unknown;
appName: string;
siteName: string;
apiKey: string;
renderView: AppRenderer;
parseRouteUrl: RouteUrlParser;
Expand Down
2 changes: 1 addition & 1 deletion packages/sitecore-jss-proxy/src/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config: ProxyConfig = {
lang: 'en',
};
},
appName: 'APP_NAME',
siteName: 'APP_NAME',
apiKey: '{GUID}',
},
};
Expand Down

0 comments on commit 3342202

Please sign in to comment.