Step 1: Create a Sample SAP CAPM Application
To begin your remote debugging journey, start by setting up a basic SAP CAPM (CAP Model) application.
1.1 Initialize the CAP Project
cds init bookshop
This creates the basic folder structure for your CAP project named bookshop.
1.2 Add a Sample Data Model
cds add tiny-sample
This adds example files for the database schema, service definitions, and sample data.
1.3 Add a Custom Action and Handler
We'll define a custom action addStock in the service file (usually under /srv) and generate a handler file for implementation.
Add the action to cat-service.cds:
action addStock(ID: Integer, quantity: Integer) returns Books;
Then generate the handler file using:
cds add handler
Step 2: Deploying the Application to Cloud Foundry
2.1 Add the MTA Descriptor
Generate the mta.yaml file, which defines the multi-target app structure:
cds add mta
mta.yaml file for deployment
this file defines a structure of the multitarget app.
---
_schema-version: 3.3.0
ID: bookshop
version: 1.0.0
description: "A simple CAP project."
parameters:
enable-parallel-deployments: true
modules:
- name: bookshop-srv
type: nodejs
path: gen/srv
parameters:
instances: 1
buildpack: nodejs_buildpack
provides:
- name: srv-api # required by consumers of CAP services (e.g. approuter)
properties:
srv-url: ${default-url}
requires: []
resources: []
2.2 Build the Project
Compile and generate build artifacts:
cds build
Once the above command is executed we will have the below folders created in our bookshop app
2.3 Create the MTAR Package
mbt build
This command packages your app (db, srv, etc.) into a .mtar archive for deployment.
2.4 Login to Cloud Foundry
Login to Cloundry foundry via the BAS or VSCode using the below command.
cf login -a <api_endpoint> --sso
You'll receive a link to authenticate and retrieve a one-time passcode for login.
The api endpoint can be found as shown in below image.
this will give link to generate the temproary passcode for logging in in to cloud foundry.
once the above command is executed, a mta archive file also known as mtar file is generated, which we will be using for deploying the application to cloud foundry using the below command.
cf deploy bookshop_1.0.0.mtar
Important Note
To ensure that the deployment doesnt fail, ensure to make the authentication as mock in package.json file before running the cds build command.
{
"name": "bookshop",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@sap/cds": "^9",
"express": "^4"
},
"engines": {
"node": "^22"
},
"devDependencies": {
"@cap-js/cds-types": "^0.10.0",
"@cap-js/sqlite": "^2",
"@sap/cds-dk": ">=8"
},
"cds": {
"requires": {
"auth": {
"kind": "mocked" // Using mocked authentication
}
}
},
"scripts": {
"start": "cds-serve",
"login":" cf login -a <api_endpoint> --sso",
"ssh":"cf ssh bookshop-srv",
"remote-debug":"cds debug bookshop-srv"
}
}
Once the application is deployed, we can see the application in our BTP subaccount under cloudfoundry dev spaces.
Step 3: - Remote Debugging of SAP CAPM App.
Copy the app URL from BTP as shown in screenshot, to trigger the debugger via postman or chrome.
3.1 Establish an SSH Tunnel
Before we start with remote debugging, we need to use the below command to establish ssh tunnel[ basically secure tunnel to communicate with our app] between our app container in cloud foundry and VSCODE/BAS
cf ssh bookshop-srv
3.2 Start Debug Mode
In a new terminal, run:
cds debug bookshop-srv
If Chrome DevTools fails to open automatically, don’t worry. You can open the debugger manually.
chrome://inspect
3.3 Open Chrome Inspector
In Chrome, go to:
chrome://inspect
Click "inspect" under "Remote Target" to open the debugging interface like the below.
now trigger the request from postman
The debugger is triggered in window.
Happy Debugging !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
8 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 |