Next.js for SitecoreAI environment variables

Version: 22.x

Starting from JSS version 21.6, the SITECORE_EDGE_CONTEXT_ID variable (Context ID) replaces many environment variables that were previously required. However, you must continue to use certain variables when developing locally in a full-stack scenario (since Context ID does not apply). The following sections contain the variables used in each environment type.

The following are the supported variables for Next.js for SitecoreAI:

Variable name

Description

Usage

SITECORE_EDGE_CONTEXT_ID

The Context ID, which covers many system configurations required for connecting to the SitecoreAI back end. This is a SitecoreAI system environment variable. When the application runs on the SitecoreAI rendering host, this value is always set to the preview Context ID.

Environments connected to SitecoreAI, local front-end development

SITECORE_API_KEY

The API key for GRAPH_QL_ENDPOINT authentication. For Experience Edge, you can find the API key in the Sites dashboard by opening the actions menu for a site and navigating to Settings > Developer settings. Copy the value for SITECORE_API_KEY. For a preview endpoint (a CM instance either on SitecoreAI or locally), use your SitecoreAI preview API Key. When the application runs on the SitecoreAI rendering host, this value is always set to your Sitecore Services Client API Key, and it will override any value set in your .env file.

Local full-stack development with a local Docker Sitecore environment

SITECORE_API_HOST

The API hostname, needed to build the application. When the application runs on the SitecoreAI rendering host, this value is always set to your content management instance, and it will override any value set in your .env file. For example, https://<sitecoreai_cm_host>.sitecorecloud.io.

Local full-stack development with a local Docker Sitecore environment

GRAPH_QL_ENDPOINT

The GraphQL endpoint. For Experience Edge, the value is https://edge.sitecorecloud.io/api/graphql/v1. For a preview endpoint (a CM instance on SitecoreAI or a local one), the value is <sitecoreai_cm_host>/sitecore/api/graph/edge. When the application runs on the SitecoreAI rendering host, this value is always set to the preview endpoint for your CM instance <sitecoreai_cm_host>/sitecore/api/graph/edge , and it will override any value set in your .env file.

Local full-stack development with a local Docker Sitecore environment

PUBLIC_URL

Important

This environment variable is only needed if you're using the older, chromes-based editing mode for Pages. If you're using the newer, metadata-based editing mode, you can omit this variable.

The public URL for absolute URLs required for static assets when the Next.js app runs in an editing environment. This is a SitecoreAI system environment variable. When the application runs on the SitecoreAI rendering host, this value is always set to your rendering host instance, and it will override any value set in your .env file. For example, https://<sitecoreai_cm_host>.sitecorecloud.io. This variable is required only to support Sitecore editors, so in non-editing environments, it needs to be set to empty string to have relative URLs. Also, if defined, PUBLIC_URL takes precedence over the Vercel/Netlify environment variables (used in Vercel/Netlify deployments), so the values of these variables must be adjusted as needed.

JSS_EDITING_SECRET

A secret token that protects the Sitecore editor endpoint (/api/editing/render) exposed by the Next.js app. We recommend an alphanumeric value of at least 16 characters. This client-side value must match the server-side value, as set in the /sitecore/config/<SITE_NAME>.config file. This is a SitecoreAI system environment variable.

SITECORE_SITE_NAME

The name of your site. This variable overrides the config.appName defined in the package.json file. You can find this value in the Sites dashboard by opening the actions menu for a site and navigating to Settings > Developer settings.

DEFAULT_LANGUAGE

The default language of your app.

GRAPH_QL_SERVICE_RETRIES

The number of times the GraphQL Layout, Dictionary, and ErrorPages services retry to fetch when the endpoint rate limit is reached. See how to enable retries for requests to the SitecoreAI Experience Edge GraphQL endpoint.

Default: 3

FETCH_WITH

Determines how layout and dictionary data is fetched from Sitecore. The possible values are REST and GraphQL. You select the value during the app scaffold process. If the value isn't provided, the default is GraphQL.

DISABLE_SSG_FETCH

Indicates whether, during static site generation (SSG), getStaticPathspre-renders any pages. This is a SitecoreAI system environment variable. When the application runs on the SitecoreAI rendering host, this value is always true at build time and runtime for improved efficiency and stability.

DEBUG

Sitecore JSS NPM packages utilize the debug module for logging. You can use the debug mode flexibly.

Do you have some feedback for us?

If you have suggestions for improving this article,