1. Developer guides

Deploy Content SDK Angular apps to Vercel or Netlify

You can deploy a Content SDK Angular application to Vercel or Netlify with server-side rendering (SSR). The generated application uses an Express server to handle Angular rendering and Content SDK middleware. To run this server on either platform, create a serverless function that imports the compiled Angular request handler.

This topic describes how to:

  1. Prepare your application for deployment.
  2. Deploy your application.
  3. Verify your deployment.

Prepare your application for deployment

To prepare your application for deployment:

  1. In src/server.ts, ensure that the request handler has the default export for the request handler:

    export default reqHandler;
  2. Replace <app-name> in every example in this topic with your application's name set in package.json.

  3. Prepare the environment variables that your application uses to connect to SitecoreAI:

    VariableValue
    SITECORE_EDGE_CONTEXT_IDThe server context ID for your SitecoreAI environment.
    CSDK_PUBLIC_SITECORE_EDGE_CONTEXT_IDThe client context ID for browser operations.
    CSDK_PUBLIC_DEFAULT_SITE_NAMEThe name of the Sitecore site.
    CSDK_PUBLIC_DEFAULT_LANGUAGEThe default language, for example, en.

    Add any other variables required by your application. If you use the deployment as an editing host, configure SITECORE_EDITING_SECRET and the corresponding rendering host settings in SitecoreAI.

    For configuration details, see The Sitecore configuration file.

    Important

    The build includes variables prefixed with CSDK_PUBLIC_ in the browser bundle. Use the client context ID for CSDK_PUBLIC_SITECORE_EDGE_CONTEXT_ID and keep the server context ID in SITECORE_EDGE_CONTEXT_ID.

Deploy your application

See the following sections to deploy your application to Vercel and Netlify.

Create a Vercel Function that exports the compiled Angular request handler, then configure Vercel to route requests to it. This configuration uses the Node.js runtime.

To deploy your application to Vercel:

  1. In the application's root folder, create vercel/index.mjs with the following content:

    export { default } from '../dist/<app-name>/server/server.mjs';
  2. In the application's root folder, create vercel.json with the following content:

    {
      "$schema": "https://openapi.vercel.sh/vercel.json",
      "buildCommand": "npm run build",
      "outputDirectory": "dist/<your_app_name>/browser",
      "rewrites": [
        {
          "source": "/(.*)",
          "destination": "/vercel/index"
        }
      ],
      "functions": {
        "vercel/index.mjs": {
          "includeFiles": "dist/<your_app_name>/**"
        }
      }
    }

    The framework setting selects the Other preset for this custom deployment configuration. The includeFiles setting includes the Angular build output in the function so the server can access its runtime files.

  3. Commit and push the application changes to your source control repository.

  4. In the Vercel dashboard, create a project by importing the repository. Set the Root Directory to the application's root folder, which contains package.json and vercel.json.

  5. Add the Content SDK environment variables from Prepare your application for deployment. Make them available in each Vercel deployment environment that you use.

  6. Add the following Angular environment variables:

    NG_ALLOWED_HOSTS=*.vercel.app
    NG_TRUST_PROXY_HEADERS=X-FORWARDED-PORT,X-FORWARDED-PATH,X-FORWARDED-FOR,X-FORWARDED-HOST,X-FORWARDED-PROTO

    These settings allow Vercel URLs and prevent Vercel rendering from falling back to CSR.

  7. Deploy the project, then verify the deployment.

Verify your deployment

After the build and deployment complete:

  1. Open the deployment URL and confirm that the application displays the published Sitecore content.
  2. Open a nested page URL directly, then refresh the page to verify that the hosting configuration routes the request to the application.
  3. Inspect the page source for a server-rendered route and confirm that the initial HTML contains the expected page content.
  4. Navigate between pages and check that the POST /_data requests succeed and static assets load without errors.

If the application doesn't render correctly, check the hosting provider's build and function logs. Confirm that the build output paths match the function imports and configuration files, and that NG_ALLOWED_HOSTS includes the deployment hostname. Check NG_TRUST_PROXY_HEADERS if Angular doesn't resolve the request URL correctly behind the hosting proxy.

Rebuild and redeploy after changing public environment variables because the build includes their values in the browser bundle.

These deployments run the Express server as a serverless function. The hosting provider's function limits apply. See Vercel Functions limits and Netlify function configuration and limits.

If you have suggestions for improving this article, let us know!