Prepare for Production
As you've followed the tutorials for the Incident Management application, you’ve developed an application with an in-memory database and basic authentication. To have such an application on production, you need to make the respective configurations.
Overview
You will learn
- How to configure SAP HANA Cloud in your project.
- How to configure the SAP Authorization and Trust Management service in your project.
Prerequisites
Prerequisites
You’ve added test cases in your application. Follow the steps in the Add Test Cases tutorial that is part of the Develop a Full-Stack CAP Application Following SAP BTP Developer’s Guide tutorial group.
OUT OF MAINTENANCE
This tutorial is no longer maintained. For an up-to-date version and support with any issues, refer to the Develop a Full-Stack CAP Application Following the SAP BTP Developer’s Guide mission in the SAP Discovery Center.
Steps
You can create a CAP project in either Node.js or Java. You have to choose one way or the other and follow through. The tabs Node.js and Java provide detailed steps for each alternative way.
In SAP Business Application Studio, go to your IncidentManagement dev space.
Make sure the IncidentManagement dev space is in status RUNNING.
From the root of the INCIDENT-MANAGEMENT project, choose the burger menu, and then choose Terminal → New Terminal.
To add an SAP HANA Cloud client to your application, run the following command:
Shellcds add hana --for productionThe cds add hana command adds the
@sap/cds-hanamodule that allows SAP HANA Cloud to access the package.json file and the database configuration"db": "hana"that uses SAP HANA Cloud when the application is started on production.The cds add hana command adds to the package.json file the
"@cap-js/hana": "^x"dependency and thecds.requires[production]profile"db": "hana".JSON{ "name": "incident-management", "dependencies": { ... "@cap-js/hana": "^x" }, ... "cds": { "requires": { ... "[production]": { "db": "hana" } } } ... }To learn more, see:
By default, these profiles are available:
- For local testing: development
- For hybrid testing: hybrid
- For productive testing: production
Deployments are done using the production profile automatically. You can inspect the effective production configuration with the cds env command:
Shellcds env requires -4 productionThe output of this command looks like this:
Shell{ middlewares: true, auth: { kind: 'jwt', vcap: { label: 'xsuaa' } }, db: { impl: '@sap/cds/libx/_runtime/hana/Service.js', kind: 'hana' } }Verify that your application still works locally. If you closed it, choose the Preview Application option in the Application Info - incidents tab and select the watch-incidents npm script.
To open the Application Info - incidents tab:
- Invoke the Command Palette - View → Command Palette or Command + Shift + P for macOS / Ctrl + Shift + P for Windows.
- Choose Fiori: Open Application Info.
In SAP Business Application Studio, go to your IncidentManagement dev space.
Make sure the IncidentManagement dev space is in status RUNNING.
From the root of the INCIDENT-MANAGEMENT project, choose the burger menu, and then choose Terminal → New Terminal.
To add an SAP HANA Cloud client to your application, run the following command:
Shellcds add hana --for productionThe cds add hana command adds a dependency that contains
cds-feature-hanadependency which is used to configure hana as production database.The cds add hana command adds to the srv/pom.xml file the highlighted lines:
XML<dependency> <groupId>com.sap.cds</groupId> <artifactId>cds-starter-cloudfoundry</artifactId> </dependency>To learn more, see:
By default, these profiles are available:
- For local testing: development
- For hybrid testing: hybrid
- For productive testing: production
Deployments are done using the production profile automatically. You can inspect the effective production configuration with the cds env command:
Shellcds env requires -4 productionThe output of this command looks like this:
Shell{ db: { impl: '@sap/cds/libx/_runtime/hana/Service.js', kind: 'hana', 'deploy-format': 'hdbtable' }, auth: { strategy: 'JWT', kind: 'jwt-auth', vcap: { label: 'xsuaa' } }, approuter: { kind: 'cloud-foundry' } }Verify that your application still works locally. Navigate to the srv folder.
Shellcd srvRun the following command to start a CAP Java server:
Shellmvn cds:watchIn the bottom right of your SAP Business Application Studio window, look for the popup A service is listening to port 8080.
Choose Open in a New Tab.

Open in a new tab You see the generic
index.htmlpage:
index.html
Stop the CAP server with Ctrl + C and start it again with the
mvn cds:watchcommand.
Run the following command in the terminal:
Shellcds add xsuaa --for productionRunning cds add xsuaa does two things:
- Adds the SAP Authorization and Trust Management service (including the
"@sap/xssec": "^x"dependency and thecds.requires[production]profile"auth": "xsuaa") to the package.json file of the INCIDENT-MANAGEMENT project. - Creates the SAP Authorization and Trust Management service security configuration (that is, the xs-security.json file) for the INCIDENT-MANAGEMENT project.
- Adds the SAP Authorization and Trust Management service (including the
Make sure that the SAP Authorization and Trust Management configuration has been added to the package.json file:
JSON{ "name": "incident-management", "dependencies": { ... "@sap/xssec": "^x" }, ... "cds": { "requires": { ... "[production]": { "db": "hana", "auth": "xsuaa" } ... } } }In case any of the lines is missing, go ahead and add it manually.
Check the content of the xs-security.json file.
You have already added authorizations with the requires annotations in the CDS service model (that is the services.cds file in the srv folder). See Add Authorization.
CDSusing { sap.capire.incidents as my } from '../db/schema'; /** * Used by support team members to process incidents */ service ProcessorService { ... } annotate ProcessorService.Incidents with @odata.draft.enabled; annotate ProcessorService with @(requires: 'support'); service AdminService { ... } annotate AdminService with @(requires: 'admin');
These authorizations are now translated into scopes and role templates for the SAP Authorization and Trust Management service. Hence, a scope and a role template are created in the xs-security.json file for the support role and for the admin role:
{
"scopes": [
{
"name": "$XSAPPNAME.support",
"description": "support"
},
{
"name": "$XSAPPNAME.admin",
"description": "admin"
}
],
"attributes": [],
"role-templates": [
{
"name": "support",
"description": "generated",
"scope-references": [
"$XSAPPNAME.support"
],
"attribute-references": []
},
{
"name": "admin",
"description": "generated",
"scope-references": [
"$XSAPPNAME.admin"
],
"attribute-references": []
}
]
}You can learn more about authorization in CAP in CDS-based Authorization.
Run the following command in the terminal:
Shellcds add xsuaa --for productionRunning cds add xsuaa does two things:
- Adds the SAP Authorization and Trust Management service to the srv/pom.xml file of the INCIDENT-MANAGEMENT project.
- Creates the SAP Authorization and Trust Management service security configuration (that is, the xs-security.json file) for the INCIDENT-MANAGEMENT project.
Check the content of the xs-security.json file.
You have already added authorizations with the requires annotations in the CDS service model (that is the services.cds file in the srv folder). See Add Authorization.
CDSusing { sap.capire.incidents as my } from '../db/schema'; /** * Used by support team members to process incidents */ service ProcessorService { ... } annotate ProcessorService.Incidents with @odata.draft.enabled; annotate ProcessorService with @(requires: 'support'); service AdminService { ... } annotate AdminService with @(requires: 'admin');
These authorizations are now translated into scopes and role templates for the SAP Authorization and Trust Management service. Hence, a scope and a role template are created in the xs-security.json file for the support role and for the admin role:
{
"scopes": [
{
"name": "$XSAPPNAME.support",
"description": "support"
},
{
"name": "$XSAPPNAME.admin",
"description": "admin"
}
],
"attributes": [],
"role-templates": [
{
"name": "support",
"description": "generated",
"scope-references": [
"$XSAPPNAME.support"
],
"attribute-references": []
},
{
"name": "admin",
"description": "generated",
"scope-references": [
"$XSAPPNAME.admin"
],
"attribute-references": []
}
]
}You can learn more about authorization in CAP in CDS-based Authorization.
You can create a CAP project in either Node.js or Java. You have to choose one way or the other and follow through. The tabs Node.js and Java provide detailed steps for each alternative way.
Run the following command in the terminal:
Shellcds add workzone-standardMake sure that the lines
"destinations": true,"html5-repo": true, and"workzone": truehave been added to the package.json file:JSON{ "name": "incident-management", "dependencies": { ... }, ... "cds": { "requires": { ... "[production]": { ... }, "destinations": true, "html5-repo": true, "workzone": true } ... } }In case any of the lines is missing, go ahead and add it manually.
Check the content of the app/incidents/package.json file:
JSON{ "name": "incidents", "version": "0.0.1", "description": "An SAP Fiori application.", "keywords": [ "ui5", "openui5", "sapui5" ], "main": "webapp/index.html", "dependencies": {}, "devDependencies": { "@ui5/cli": "^3.0.0", "@sap/ux-ui5-tooling": "1", "ui5-task-zipper": "^3" }, "scripts": { "deploy-config": "npx -p @sap/ux-ui5-tooling fiori add deploy-config cf", "build": "ui5 build preload --clean-dest --config ui5-deploy.yaml", "build-local": "ui5 build preload --clean-dest", "start": "ui5 serve" }, "ui5": { "dependencies": [ "ui5-task-zipper" ] } }Check the newly created file ui5-deploy.yaml in the folder app/incidents/.
YAML# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json specVersion: '3.1' metadata: name: incidents type: application resources: configuration: propertiesFileSourceEncoding: UTF-8 builder: resources: excludes: - "/test/**" - "/localService/**" customTasks: - name: ui5-task-zipper afterTask: generateVersionInfo configuration: archiveName: incidents additionalFiles: - xs-app.jsonVerify that the navigation target
incidents-displayand the SAP Cloud servicesap.cloudhave been correctly added to the application manifest file app/incidents/webapp/manifest.json:JSON"sap.app": { "id": "ns.incidents", ... "sourceTemplate": { ... }, "dataSources": { ... }, "crossNavigation": { "inbounds": { "incidents-display": { "semanticObject": "incidents", "action": "display", "signature": { "parameters": {}, "additionalParameters": "allowed" } } } } ... "sap.cloud": { "public": true, "service": "incidentmanagement.service" } }Open app/incidents/webapp/manifest.json and remove the leading
/from theuriparameter.JSON{ "_version": "1.49.0", "sap.app": { "id": "ns.incidents", "type": "application", "i18n": "i18n/i18n.properties", ... "dataSources": { "mainService": { "uri": "odata/v4/processor/", "type": "OData", "settings": { "annotations": [], "localUri": "localService/metadata.xml", "odataVersion": "4.0" } } }, ... }, ... }Removing the leading
/is needed as the dataSource URIs must be relative to the base URL, which means there’s no need for a slash as the first character.Check Accessing Business Service UI for more information.
Make sure that the line
"welcomeFile": "/index.html"in the following snippet is added to the app/incidents/xs-app.json file. Add if it’s missing.JSON{ "welcomeFile": "/index.html", "authenticationMethod": "route", "routes": [ { "source": "^/?odata/(.*)$", "target": "/odata/$1", "destination": "incident-management-srv-api", "authenticationType": "xsuaa", "csrfProtection": true }, { "source": "^(.*)$", "target": "$1", "service": "html5-apps-repo-rt", "authenticationType": "xsuaa" } ] }In the terminal, navigate to the app/incidents/ folder and run the following command:
Shellnpm install
Run the following command in the root folder of your project:
Shellcds add workzoneYou see the following output in the terminal:
ShellAdding feature 'destination'... Adding feature 'html5-repo'... Adding feature 'workzone'... Adding feature 'workzone-standard'...Open app/incidents/webapp/manifest.json and remove the leading
/from theuriparameter.JSON{ "_version": "1.49.0", "sap.app": { "id": "ns.incidents", "type": "application", "i18n": "i18n/i18n.properties", ... "dataSources": { "mainService": { "uri": "odata/v4/processor/", "type": "OData", "settings": { "annotations": [], "localUri": "localService/metadata.xml", "odataVersion": "4.0" } } }, ... }, ... }Removing the leading
/is needed as the dataSource URIs must be relative to the base URL, which means there’s no need for a slash as the first character.Check Accessing Business Service UI for more information.
Navigate to the db folder in the terminal and run the following command:
Shellnpm installNavigate to the app/incidents folder in the terminal and run the following command:
Shellnpm install
To validate that everything is prepared as expected, run a test build. Navigate to your project’s root folder in the terminal and run the following command:
cds build --productionYou get an output like:
[cds] - build completed in 511 msTo validate that everything is prepared as expected, run a test build. Navigate to your project’s root folder in the terminal and run the following command:
mvn clean packageYou get an output like:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.848 s
[INFO] Finished at:
[INFO] ------------------------------------------------------------------------Now that you’ve prepared your CAP application for deployment, you can choose from the following deployment options:
- Follow the tutorials in the Deploy a Full-Stack CAP Application in SAP BTP, Cloud Foundry Runtime Following SAP BTP Developer’s Guide group to deploy the application in the SAP BTP, Cloud Foundry runtime.
- Follow the tutorials in the Deploy a Full-Stack CAP Application in SAP BTP, Kyma Runtime Following SAP BTP Developer’s Guide group to deploy the application in the SAP BTP, Kyma runtime.
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.