Deploy your front-end application to Netlify

Netlify is a cloud computing company that offers a development platform that includes build, deploy, and serverless backend services for web applications and dynamic websites. Netlify has first-class support for Next.js.

You can set up continuous deployment (CD) in Netlify to redeploy your Content SDK Next.js app whenever you publish code changes to your source control repository. This procedure assumes that you're deploying the Next.js application from the project repository, which includes the instance and the front-end solution.

This procedure does not describe how to implement automatic redeploys when you make changes to your SitecoreAI content. You can decide for yourself how best to implement this, according to the recommendations provided by Netlify.

Before you begin
  • Ensure you have a Netlify account that you're logged in to.

  • Ensure you have the SITECORE_EDGE_CONTEXT_ID and NEXT_PUBLIC_DEFAULT_SITE_NAME environment variables for your deployment, and any other relevant variables (including custom ones).

  • If you made code changes in your local development environment, commit and push your code. If you set up your environment to redeploy when pushing changes to the configured branch, allow the redeployment to complete.

  • If you made content and layout changes in a local environment, use the Sitecore CLI to publish your changes and verify that your content is on Edge.

  • In your SitecoreAI instance, publish all the changes you want to make available on your website.

  • In your Next.js application, commit and push your changes to your source control repository.

To deploy your front-end application to Netlify:

  1. In your Netlify account, follow the Netlify documentation for adding a new site based on an existing repository. Choose a different branch if you don't want to deploy the application from your default branch.

  2. In the Build settings section, in the Base directory field, enter the path to the root folder of the Next.js application. We're using the Skate Park example from the starter JS repository for which the path is examples/kit-nextjs-skate-park.

    Netlify tries to populate additional fields based on your base directory. Verify that the auto-completed values are as follows:

    • Publish directory: examples/kit-nextjs-skate-park/.next.

    • Functions directory: examples/kit-nextjs-skate-park/netlify/functions. If you created custom serverless functions in a different directory, specify that directory here.

    • Build command: npm run build.

    For more information, see the Netlify Build configuration documentation.

    Important

    We're deploying the Skate Park sample in the starter repository as it contains a few components out-of-the-box. For a real project, you'll most likely start from an empty project like examples/basic-nextjs (for Next.js projects) or examples/basic-spa (for Angular projects).

  3. Click Add environment variables and enter the following variables:

    • SITECORE_EDGE_CONTEXT_ID - your unified Context ID. Use the Preview Context ID for all content and layout data, or the Live Context ID for published data only.

    • NEXT_PUBLIC_DEFAULT_SITE_NAME - the name of the site.

    • Add other environment variables (SITECORE_EDGE_URL, NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID, SITECORE_EDITING_SECRET) including custom environment variables you've added to your .env file. Netlify recommends that all environment variables be added to the Netlify site configuration.

      Note

      You don't need to set environment variables for Personalize and other Sitecore product integrations. They are included in your Sitecore Context and automatically provided to the application and integrations. An exception is Sitecore Search.

  4. Click Deploy site.

  5. When the Netlify deployment process finishes, verify that the deployed application hosted by Netlify renders as expected.

Troubleshooting the CD setup

At the end of the deployment process, even though Netlify reports that the site was successfully built and deployed, you may see a Netlify 404 error page instead of the expected pages.

The most likely reason is that, because of the nested location of the Next.js Content SDK app in a project repository, Netlify could not detect that the application is a Next.js application and failed to set the correct runtime.

After your site is created in Netlify:

  1. In your Netlify dashboard, navigate to the site's configuration area.

  2. In the Build & Deploy section, in the Build settings, click Configure.

  3. Find the Runtime setting and select Next.js.

  4. Redeploy the site.

Do you have some feedback for us?

If you have suggestions for improving this article,