Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
sabarna17
Contributor

  Intro






 

Hello there. Hope you are doing well.

In this blog, I am going to share some methods which might be easen up deployments and developments in CAPM  - "The SAP Cloud Application Programming Model is a framework of languageslibraries, and tools for building enterprise-grade services and applications"

Readers, please make a note that, this is not related to the actual CAPM tutorial. You must have some prior understanding of these - VS Code, SCP-CFNodeJS, and CAPM.

 

What you are getting here:

  1. Auto CF Login from your Windows PC.

  2. how to create a custom API in SAP CDS - Build Custom API parallel to CDS Services

  3. Deploy your CAPM in GCP ie Deploy your CAP in the GCP APP Engine. | SAP CDS on GCP


 

  Let's do it






 

Here is -


Git-Link.


Linked-In


 

1. Auto Start CF Login for Windows - Git-Rep


 

.bat file is a special text file where you can run multiple commands sequentially. This helps to automate several processes. Now its turn to change your life a lot...????

Just kidding. It's not - you still have to code.??

CF-CLI is an easy way to push your code in SCP-CF.

Create a .bat file as - (https://github.com/sabarna17/sample-capm-gcp-vm/blob/main/cf%20bat/cflogin.bat)

To make the login as an auto-start need to create a shortcut of the bat file and save the shortcut in the following path:
C:\Users{user}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Vola.

Restart and Check now. While switching on your Windows machine, CF will be automatically logged in every time.

You can also use these .bat files to automate and run your multiple and complex deployments in a go. So start batting.??


 

2.Custom NodeJS API with CDS Service? - Git Rep


 

While creating a CAP project have you tried to write a freehand NodeJS and deploy parallelly to the CDS Services? If the answer is yes, please mention your strategy commenting about it.

What you are getting here is :


You can create a CDS Service and write some NodeJS scripts and enhance the existing modules.



What I thought about CDS:



  1. The custom output structure is hard to expose.

  2. Free custom SQLite syntax can not be executed

  3. Full Control along with the API


 

Solution:


Create a CDS Project and deploy your CDS Tables to Sqlite.

 

The below technique is just a way to enhance the way we can write code in NodeJS

  1. Create a myCustAPI.js file as given here myCustAPI.js
    module.exports =
    {
    custAPI: function (app) {
    const express = require('express');
    const bodyParser = require('body-parser');
    const { urlencoded } = require('body-parser');
    var fullpath = __dirname.replace("/\\", '/');

    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(express.static("public"));
    app.use(bodyParser.json());

    app.get("/API_without_CDS", function (request, response) {
    function_API_without_CDS(request, response);
    });

    return app;
    }
    }

    function function_API_without_CDS(request, response){
    var query = request.query;
    if (query.VAL1 && query.VAL2) {
    response.json({ 'query': query, 'sample_query': query.VAL1 + query.VAL2 });
    }
    }


  2. Change the existing CDS 'server.js' file - node_modules>@sap>cds>server.js

    • To change the file use reference code from server.js file



  3. Check the changes in the existing server.js - line no - 29,57


 

Testing from Postman:


You can now execute two below URLs from the postman and test it:

  1. CDS service - http://localhost:4004/catalog/Books I know you are a bit confused about the language in "descr" field value for "ID": "101". FYI that's Bengali.


 

2. Your API - http://localhost:4004/API_without_CDS .

 

Note:


http://localhost:4004/API_without_CDSThis API accepts two query parameters - VAL1 and VAL2 and returns the concatenation of both.

 

Moving on to the Last section:


 

3. Deploy your CAP Project in GCP. Git Rep


 

Here I have tried to deploy a CDS Project to GCP.

Prerequisite



  1. GCP account is active. If no, click here and see details - GCP

  2. You have tested your CAPM-NodeJS code Locally. You can run your CDS services - (http://localhost:4004/) and it works fine.


Deployment Steps



  1. Install GCP Cli from the below link - GoogleCloudSDKInstaller

  2. Authenticate to Google Cloud by the below command. While authenticating it might open a browser and ask for Authentication to your GCP



gcloud auth login

 



  1. Set your Project for GCP for GCP-Cli



gcloud config set project tidal-analogy-XXXXXXX

 



  1. Now we need to change the package(my-bookshop) a bit.

    • Create a .yaml file name app.yaml inside the package my-bookshop



    runtime: nodejs12
    service: my-bookshop

     



    • Your package will look like -



    my-bookshop/
    app
    db
    srv
    app.yaml
    package.json
    package-lock.json
    myCustAPI.js
    README.md

     


  2. Now let's deploy with the below command:



gcloud app deploy


deployment

  1. Your API is not being hosted in GCP:


CDS-in-GCP

 
Ta da it got deployed


  1. You can test now through postman:


CDS-in-GCP

Read more


Create a GCP account (https://cloud.google.com/appengine/docs/standard/nodejs/building-app)

Common Error


I tried to deploy several times but getting a strange error - "Internal server error" whenever I was executing Catalog URLs. Then I found a resolution to this. I added a "prestart" command as given in the file: package.json file

 

 

  Conclusion






 

I have started to work on CAP and NodeJS recently. So trying out different things about the CAP and here is what I thought might be interesting to you. I try to explore more about the SAP offerings.

Note:


1. If you have any substitutable solution for 'Hack no 2', please comment about it.


2. I tried to Mix - 'Hack no 2' to 'Hack no 3'. It didn't work. Feel free to comment if you have any solution for this.


Thanks for Reading.. ???

Please comment on your thoughts..

5 Comments
Labels in this area