- 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:
Prepare your application for deployment
To prepare your application for deployment:
-
In
src/server.ts, ensure that the request handler has the default export for the request handler: -
Replace
<app-name>in every example in this topic with your application's name set inpackage.json. -
Prepare the environment variables that your application uses to connect to SitecoreAI:
Variable Value 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_SECRETand the corresponding rendering host settings in SitecoreAI.For configuration details, see The Sitecore configuration file.
ImportantThe build includes variables prefixed with
CSDK_PUBLIC_in the browser bundle. Use the client context ID forCSDK_PUBLIC_SITECORE_EDGE_CONTEXT_IDand keep the server context ID inSITECORE_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:
-
In the application's root folder, create
vercel/index.mjswith the following content: -
In the application's root folder, create
vercel.jsonwith the following content:The
frameworksetting selects the Other preset for this custom deployment configuration. TheincludeFilessetting includes the Angular build output in the function so the server can access its runtime files. -
Commit and push the application changes to your source control repository.
-
In the Vercel dashboard, create a project by importing the repository. Set the Root Directory to the application's root folder, which contains
package.jsonandvercel.json. -
Add the Content SDK environment variables from Prepare your application for deployment. Make them available in each Vercel deployment environment that you use.
-
Add the following Angular environment variables:
These settings allow Vercel URLs and prevent Vercel rendering from falling back to CSR.
-
Deploy the project, then verify the deployment.
Use a Netlify Functions v2 handler with the .mts extension to preserve the ECMAScript module (ESM) format required by the compiled Angular server. The handler uses serverless-http to adapt Netlify's web Request and Response objects to the Express request handler.
The named handler export in Netlify's Express deployment example uses the Lambda-compatible API. For this Angular deployment, use the default export shown below. See Netlify function module formats.
To deploy your application to Netlify:
-
The
serverless-httpmodule provides the required bridge between Express and Netlify. You should install it alongside few additional dependencies that your Netlify function will use. In the application's root folder, install the function dependencies: -
Create
netlify/functions/server.mtswith the following content:The function imports Angular's SSR artifacts and transforms them to be used by
serverless-httpand v2 functions. These transformations are needed for the Netlify CLI to correctly identify the function as ESM-compatible. This example TypeScript function is assumed to be present inside thenetlify/functions/server.mtsfile. -
In the application's root folder, create
netlify.tomlwith the following content: -
Commit and push the application changes, including the updated dependency files, to your source control repository.
-
In Netlify, create a project from the repository. If the application is in a subfolder, set the Base directory to the application's root folder. Confirm that Netlify uses the build, publish, and functions paths in
netlify.toml. -
Add the Content SDK environment variables from Prepare your application for deployment. Ensure that the connection variables are available during the build and to the deployed function. The build includes public variables in the browser bundle.
-
Add the following Angular environment variables for the deployed function:
These settings allow netlify URLs and ensure Angular SSR works correctly from behind the Netlify proxy.
-
Deploy the project, then verify the deployment.
Verify your deployment
After the build and deployment complete:
- Open the deployment URL and confirm that the application displays the published Sitecore content.
- Open a nested page URL directly, then refresh the page to verify that the hosting configuration routes the request to the application.
- Inspect the page source for a server-rendered route and confirm that the initial HTML contains the expected page content.
- Navigate between pages and check that the
POST /_datarequests 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.