Node XM Cloud Proxy
The JSS Node.js-based proxy app is the backbone for enabling seamless integration between SitecoreAI and various SPA frameworks like React, Angular, and Vue. At launch, it supports the JSS Angular starter kit, and it will lay the foundation for future JSS starter kits built for other front-end JavaScript frameworks. It acts as a middleware layer to handle critical functionalities such as server-side rendering (SSR), and to enable editing and personalization, A/B/n component testing, and Sitecore Forms integration.
By serving as the rendering host, the proxy ensures a smooth connection between SitecoreAI services and your front-end applications, making it easier to build dynamic, personalized, and localized experiences for users.
The XM Cloud Proxy is in public beta. If you encounter any issues or bugs, please submit a new issue in the JSS GitHub repo.
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
This is a sample setup showing how you can configure SitecoreAI rendering server on top of Node.js and Express.js
The proxy does not support deployment to Vercel.
Getting started
Here are the main configurations defined in the config.ts file in the node XM Cloud proxy app:
-
Server bundle configuration:
-
The app loads a
server.bundle.jsfile, pre-built from your SPA. -
This file contains the required configuration options.
-
-
GraphQL endpoint setup:
-
Defines a
graphQLEndpointfor handling Sitecore GraphQL requests. It differentiates between production (Sitecore Edge) and development (Sitecore CM) endpoints. -
Constructs the target URL and path for proxy requests, ensuring compliance with
http-proxy-middlewarerequirements.
-
-
Port configuration:
-
Configures the port for running the proxy, with a default of
3000or an environment-specified port.
-
-
Personalization configuration (
personalizeConfig):-
Sets up Sitecore personalization through
PersonalizeConfig, defining settings for both Sitecore Experience Edge and CDP endpoints. -
Contains options to control personalization features, including:
-
Timeouts for Edge and CDP endpoints (default 400ms, configurable via environment variables).
-
Scope and site name used for Sitecore Personalize.
-
Enable/Disable Switch - functions that allow you to conditionally disable personalization based on the environment (such as disabling it in development mode) and and cookie consent policy.
-
Language configuration -
defaultLanguageserves as a fallback if language data is unavailable in layout data.
-
-
This configuration is designed to be flexible and secure, with dynamic settings managed via environment variables where appropriate.
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
Environment variables
The following environment variables can be used to configure the Node XM Cloud Proxy app instead of modifying config.js. You can use the .env file located in the root of the app, or you can set these directly in the environment (for example, in containers).
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
|
Parameter |
Description |
|---|---|
|
|
Path to the JSS SPA app's |
|
|
Optional. Port used when you start the sample app. The default value is set in |
|
|
Optional. Debug level for the proxy. To see all logs, set the
|
|
|
Required when working with the Sitecore Editor to secure the |
|
|
Optional. Timeout (ms) for Sitecore CDP requests to respond within. Default is 400. |
|
|
Optional. Timeout (ms) for Sitecore Experience Edge requests to respond within. Default is 400. |
Build and deploy a Node Proxy app for XM Cloud
Deploying a JSS application allows it to be used as an editing host in SitecoreAI. SPAs support SitecoreAI out of the box.
The following walkthrough describes how to:
It is not currently possible to deploy Node Proxy apps to Vercel.
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
Build your SPA bundle with
jss buildornpm run build, and place the output in thedistfolder.
Run your application
To run your application:
-
Run
npm install. -
Run
npm run start.
Deploy your application to Netlify
To deploy your application to Netlify:
-
In the parent directory of your Node XM Cloud Proxy app (which also contains your SPA), do the following:
XM Cloud is now SitecoreAISome code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
Run
npm init. -
In the resulting
package.jsonfile, add the following:ImportantIn all code samples, make sure you replace {:placeholder-token:}placeholders{/:placeholder-token:} with the actual values for your apps.
-
-
Make sure your
<PROXY_APP_NAME>/package.jsonfile includes the following commands for handling the build and install steps: -
Configure
serverless-httpas follows:-
Install the npm package by running the following command:
-
In your
<PROXY_APP_NAME>/src/index.tsfile, add the following import and export statements:
-
-
Create a
netlify.tomlfile and add the following Netlify configurations to it:-
This part allows the proxy app to be treated as Netlify functions:
-
This part might be required to ensure static assets can be properly accessed:
-
By default, redirects aren't applied if there's a file with the same path as the one defined in the
fromproperty. If you setforcetotrue, the redirect rule will take precedence over existing files. For example: -
This is the required build command:
-
-
Create your Netlify deployment as follows:
-
Configure all necessary environment variables, such as
SITECORE_EDGE_CONTEXT_ID,SITECORE_SITE_NAME, and so on. -
In your site settings, on the Build and Deploy tab, configure your build settings. The following is a sample configuration:
Field
Value
Base Directory
/Build command
npm run buildPublish directory
/proxy/distFunctions directory
/proxy/src
NoteIf Netlify doesn't recognize
/proxy/distas your publish directory, make sure that yourPROXY_BUILD_PATHenvironment variable uses a Unix-style format such as../proxy/dist. -