Skip to Content
Technical Articles

Deploying Applications into SAP BTP CloudFoundry: Part 1

Tutorial Overview:

This blog provides an overview on how to deploy an application into SAP Cloud Platform CF environment (now known as BTP).

At the end of this blog you will learn about:

  • Know what an approuter is.
  • Understand the basics of application deployment into SAP BTP.

What is an application router?

A application router also know as approuter is a nodejs application which serves as a single point of entry for all the other applications running in cloud foundry environment in SCP(now know as BTP i.e. Business Technology Platform).

Why do we need Application Router?

A  application running in cloud foundry environment can consist of several different microservices. Thus a central point of access is required which will not only authenticate but also forward(route) the incoming request to the respective microservices.

Hmm,too many technical terms used in the definition. Let us address them one by one.

Cloud Foundry:

Cloud Foundry is an open source platform (PAAS*) for developing ,deploying, running and scaling applications on the cloud.

MicroServices:

Microservices is an architectural style wherein an application is structured as a collection of independent services.

 

Steps to deploy a simple nodejs application into Cloud Foundry:

1. Create a new directory and initialise a Node.js Project via command:

npm init​

Note: It will create a package.json file in the root directory.

Example package.json looks like:

{
  "name": "<app-name>",
  "version": "1.0.0",
  "description": "<app-description>",
  "author": "<author-name>",
  "license": "ISC"
}

 

2. Install approuter and configure its dependency:

npm install @sap/approuter --save​

 

3. Make approuter as the starting point of this Node.js application .
It is done by adding the following script in package.json file:

"scripts": {
    "start": "node node_modules/@sap/approuter/approuter.js"
}

Example package.json looks like:

{
  "name": "<app-name>",
  "version": "1.0.0",
  "description": "<app-description>",
  "scripts": {
    "start": "node node_modules/@sap/approuter/approuter.js"
  },
  "author": "<author-name>",
  "license": "ISC",
  "dependencies": {
    "@sap/approuter": "^10.0.0"
  }
}

 

4. Create a file called xs-app.json with the following contents:

{
    "welcomeFile" : "index.html",
    "authenticationMethod" : "none"
}

Note: xs-app.json is the application router configuration file.
Thus as the name suggests all the routes of the application are defined is the application descriptor file.

 

5. Create a file called index.html inside folder resources with the following content:

Hello World

 

6. Create a file called manifest.yml with the following contents:

---
applications:
  - name: <app-name>
    buildpack: nodejs_buildpack
    memory: 512M

Note:

Manifest.yml also know as deployment descriptor file contains information needed to deploy the application on cloud foundry.

Example: name, memory, instances, path, env, and timeout.

Manifest file follows general YAML conventions like:

  • The manifest begins with three dashes
  • The applications block begins with a heading followed by a colon
  • The app nameis preceded by a single dash and one space
  • Subsequent lines in the block are indented two spaces to align with name

 

7. Deploying the applications into SAP BTP
The applications can be deployed into Cloud Foundry Environment via 2 ways :

7.a   via CF command line:
Login into SAP CF : cf login -a https://api.cf.eu10.hana.ondemand.com/
Enter your userid and password . Select the SubAccount and Space
Push the app via command: cf push

 

 

7.b.  via SAP BTP GUI:
Login to SAP BTP
Navigate to subaccount and space where you want to deploy the application.
Select Application -> Click on “Deploy Applications”

 

Deployed Application:

Click on the url : mynode-app.cfapps.eu10.hana.ondemand.com to launch the application.

 

File Structure :

 

package.json:

{
  "name": "mynode-app",
  "version": "1.0.0",
  "description": "simple nodejs application",
  "main": "index.js",
  "scripts": {
    "start": "node node_modules/@sap/approuter/approuter.js"
  },
  "author": "arjun.toshniwal@gmail.com",
  "license": "ISC",
  "dependencies": {
    "@sap/approuter": "^10.1.0"
  }
}

 

xs-app.json file:

{
    "welcomeFile" : "index.html",
    "authenticationMethod" : "none"
}

 

manifest.yml file:

---
applications:
  - name: mynode-app
    buildpack: nodejs_buildpack
    memory: 512M

 

index.html file:

Hello World

 

Summary:

In this blog you might have learned about approuter and how to deploy a simple nodejs application into SAP Cloud Platform (BTP) . In the next blog we will learn how to apply authentication to the applications deployed in Cloud Foundry.

All of your feedbacks will be highly appreciated!!!

 

3 Comments
You must be Logged on to comment or reply to a post.
  • Hello Arjun,

    It was very useful and informative blog, known about  AppRouter Usage to deploy Application in Cloud Environment(BTP).

    I followed all your steps mentioned in the blog. After Pushing the App to CF I am getting the follow errors. Could you please Assist me on this issue why I am getting like this:

     

    1)Error(Crashed)

    2)Deployemnt Info

    In Deployment Info I think I am not able to get the Buildpacks. It was showing empty. Even I am given buildpack name in manifest.yml file.

    3)In SAP BTP After uploading the Application to deploy the state was not getting Started. It was showing Starting... for longtime.

     

    SAP BTP

    4) Started State is showing as indication as Red. I hope if it goes to green color. The Application may get started. But it is showing as Crashed.

    My Project Structure is as follows:

    So could you please help me out this Issue. Present I am working on this it is very needful to achieve this task. Thanks in Advance!

    Regards,

    Mamatha M

  • Can you please goto "Logs" and check the logs.

    It will give you exact cause of errors.

    If Buildpack has been given it should get detected . So lets check what it is giving us in "Logs"

    • Hello,

      Thanks for the Quick reply.

      After removing the excess code in package.json and xs-app.json files and I have created a Approuter folder separately for  "package.json" and xs-app.json files. Then the app was started.

      yeah I referred to error logs also it helped.

       

      Regards

      Mamatha