Good day fellow CAPpers,
Today I'll share one of the lessons I've learned working with CAP, something that may not be clear in the current tutorials or documentation. It's about deploying the front-end, the UI, of your CAP application in the SAP BTP's HTML5 Repository instead of creating an AppRouter, a separate Cloud Foundry application, for it.
Pre-requisite on BTP:
To display or run HTML5 applications, your BTP SubAccount will need to have one of these services enabled/subscribed:
I recommend SAP Build Work Zone, standard edition, because it's the simplest to setup. It will be used in this guide.
Assumption about your CAP project:
The guide will assume you have the standard project structure for an MTA application:
/project
/app
/my-app
...
package.json
ui5-deploy.yaml
ui5.yaml
/db
/srv
package.json
mta.yaml
Note: the database module is optional.
Considering this, your mta.yaml will require 3 modules:
These modules will require 3 resources:
The resulting mta.yaml would look like this:
_schema-version: "3.1"
ID: cap-app-id
description: CAP app with UI on HTML5 Repo
version: 1.0.0
# build parameters added by the generator
parameters:
deploy_mode: html5-repo
enable-parallel-deployments: true
build-parameters:
before-all:
- builder: custom
commands:
- npm install
- npx cds build --production
modules:
# srv
- name: my-srv
type: nodejs
path: gen/srv
build-parameters:
builder: npm
parameters:
buildpack: nodejs_buildpack
readiness-health-check-http-endpoint: /health
readiness-health-check-type: http
routes:
- route: ${space}-my-srv.${default-domain}
provides:
- name: srv-api
properties:
srv-url: ${routes/0/route}
requires:
- name: my-auth
- name: my-destination-service
# app content deployer
- name: my-deployer
type: com.sap.application.content
path: .
requires:
- name: my-repo-host
parameters:
content-target: true
build-parameters:
build-result: resources
requires:
- artifacts:
- my-app.zip
name: myapp
target-path: resources/
- artifacts:
- my-other-app.zip
name: myotherapp
target-path: resources/
# my app itself
- name: myapp
type: html5
path: app/my-app
build-parameters:
build-result: dist
builder: custom
commands:
- npm install
- npm run build:cf
supported-platforms:
[]
# my other app itself
- name: myotherapp
type: html5
path: app/my-other-app
build-parameters:
build-result: dist
builder: custom
commands:
- npm install
- npm run build:cf
supported-platforms:
[]
# app html5 repo host
- name: my-app-content
type: com.sap.application.content
build-parameters:
no-source: true
requires:
- name: my-auth
parameters:
service-key:
name: my-auth-key
- name: my-repo-host
parameters:
service-key:
name: my-repo-host-key
- name: my-destination-service
parameters:
content-target: true
parameters:
content:
instance:
existing_destinations_policy: update
destinations:
- Name: my-repo-host
ServiceInstanceName: my-html5-srv
ServiceKeyName: my-repo-host-key
sap.cloud.service: my.app
- Name: my-auth
Authentication: OAuth2UserTokenExchange
ServiceInstanceName: my-auth
ServiceKeyName: my-auth-key
sap.cloud.service: my.app
resources:
- name: my-repo-host
type: org.cloudfoundry.managed-service
parameters:
service: html5-apps-repo
service-name: my-html5-srv
service-plan: app-host
- name: my-destination-service
type: org.cloudfoundry.managed-service
requires:
- name: srv-api
parameters:
config:
HTML5Runtime_enabled: true
init_data:
instance:
destinations:
- Authentication: NoAuthentication
Name: ui5
ProxyType: Internet
Type: HTTP
URL: https://ui5.sap.com
- Name: app-dest # defined in the apps xs-app.json
Authentication: NoAuthentication
ProxyType: Internet
HTML5.ForwardAuthToken: true
HTML5.DynamicDestination: true
Type: HTTP
URL: https://~{srv-api/srv-url} # reference to the service
existing_destinations_policy: update
version: 1.0.0
service: destination
service-name: my-destination-service
service-plan: lite
- name: my-auth
type: org.cloudfoundry.managed-service
parameters:
service: xsuaa
service-plan: application
path: ./xs-security.json
config:
xsappname: my-app # update as required
tenant-mode: dedicated
EDIT: Very important: Remember to set the resources repo-host parameter HTML5Runtime_enabled to true. It generates as false and may cause you a headache until you find it.
May this post help you on your troubleshooting. Reply if you find any issues so I, and the community, can help.
Lucas Magrini Rigo
SAP Business Technology Platform SAP Cloud Application Programming Model HTML5 SAP Fiori Launchpad SAP Build Work Zone, standard edition
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 29 | |
| 25 | |
| 24 | |
| 19 | |
| 14 | |
| 13 | |
| 12 | |
| 11 | |
| 11 | |
| 11 |