Walkthrough: Connecting the Next.js application directly to the Experience Edge endpoint
The XM Cloud foundation template contains a JSS Next.js front-end application. You can run XM Cloud CM locally for development purposes, but it requires Docker with Windows Containers enabled.
As a front-end developer, you might be using a different operating system and, therefore, can not run the full XM Cloud solution locally. Furthermore, you might only be responsible for developing the front-end applications and only need access to the latest layout and content data.
You can run your local Node.js server and connect the application directly to the remote Experience Edge endpoint.
This walkthrough describes how to:
-
Connect the application to the Edge endpoint.
-
Start the client application and verify the integration.
Connect the application to the Edge endpoint
Sitecore Experience Manager Cloud (XM Cloud) is a Software-as-a-Service (SaaS) tool that provides you with content and layout information headlessly through Experience Edge. This means that you can build your front-end application against the Edge endpoint.
To connect the application to the Edge endpoint:
-
Open the XM Cloud project folder with Visual Studio Code.
-
Go to the rendering app root folder
sxastarter
. -
Create a copy of the existing
.env
file and name it.env.local
. By default, the.env.local
file is ignored by version control systems, so you don't accidentally commit local changes to your remote repository. -
Edit the following environment variable values:
-
SITECORE_EDGE_CONTEXT_ID
- Your unified Context ID. Use the Preview Context ID for published and non-published content and layout data, or the Live Context ID for published data only. -
SITECORE_SITE_NAME
- the name of the site.
-
-
Enable debugging by uncommenting the line containing
DEBUG=sitecore-jss:*,-sitecore-jss:layout
Start the client application and verify the integration
To develop client applications, you must be familiar with Next.js and the corresponding Next.js SDK. You must also start the application in connected development mode to use data from your XM Cloud instance.
To start the application:
-
In a command-line tool window, from the root of your XM Cloud project working directory, go to the directory of the front-end application, for example,
src/sxastarter
. -
Install the dependencies for the application with the command:
RequestResponsenpm install
-
In a separate terminal window, go to the directory of the front-end application and run the following command:
RequestResponsenpm run start:connected
-
To verify that you are running your application against the remote Edge endpoint, make a content change in one of the pages in your remote XM Cloud CM instance.
-
If you used the Preview Context ID, save the page.
-
If you used the Live Context ID, save and publish the page.
Reload the page to see the changes in your browser window serving the local rendering host.
-
-
Make a small but visible change in your app code. The change should become instantly visible in your local rendering host window without reloading.