Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
darshanv23
Explorer
1,410

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.

darshanv23_45-1749016304693.png

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

darshanv23_44-1749016265043.png

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

darshanv23_43-1749016244836.png

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

darshanv23_42-1749016168923.png

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.

darshanv23_41-1749016120520.png

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.

darshanv23_48-1749016956343.png

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.

darshanv23_47-1749016913229.png

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

darshanv23_49-1749017245983.png

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

darshanv23_46-1749016732790.png

Click "inspect" under "Remote Target" to open the debugging interface like the below.

darshanv23_40-1749016088602.png

now trigger the request from postman

darshanv23_39-1749016052534.png

The debugger is triggered in window.

darshanv23_38-1749016028260.png

Happy Debugging !!

3 Comments
darshanv23
Explorer
0 Kudos

# Headsup

Before establishing ssh tunnel to our app, we need to enable the ssh for our app deployed on BTP using the below command.

cf enable bookshop-srv

Once we enable the ssh for our app, we need to restart the app using the below command

cf restart bookshop-srv

 

gatsu
Explorer
0 Kudos

Hi Darshan, 

Thanks for the blog, a small correction to your comment above; to enable ssh the command is 

cf enable-ssh <app_name>

you can read more about it here: enable-ssh - Cloud Foundry CLI Reference Guide

 

 

darshanv23
Explorer
0 Kudos

Thank you gatsu for correcting