This blog series is just a simple demo of how to create any Nodejs app and run it on both local and SAP BTP platform.
Part – 1: Create nodejs application.
Part – 2: Create Authentication instance.
Part – 3: Run app locally.
This part we will run the app from BAS using the XSUAA instance.
In srv->server.js file, going to change the port 5000 to 4000.
const port = process.env.PORT || 4000;
We have to create default destinations which will be called for our local application.
Create default-env.json file under app folder. Provide the below details –
"destinations": [
{
"name": "srv-api",
"url": "http://localhost:4000/",
"forwardAuthToken": true,
"strictSSL": false
}
]
Next, We have to provide the redirect uris for our local application, in mta.yaml .
resources:
- name: basicnodejs-xsuaa
type: org.cloudfoundry.managed-service
parameters:
service: xsuaa
service-plan: application
config:
xsappname: basicnodejs-${org}-${space}
tenant-mode: dedicated
oauth2-configuration:
redirect-uris:
- https://*.hana.ondemand.com/**
- https://*.trial.applicationstudio.cloud.sap/**
Build and deploy the mta.yaml
Now we have to bind our local app with xsuaa service.
Now build and deploy the mta.yaml, as it will update xsuaa service.
To do that in an easy way, open the command palette -> CF: bind a service locally run application
Choose the required xsuaa service
This will create the .env file, which holds the binding information of the approuter apps with xsuaa service
Copy and paste it into default-env.json file. And format it to JSON.
Now create add defult-services.json file under srv folder. Make sure the file name should be same like default-services.json
Paste the credential part of the xsuaa service from app->default-env.json file
Now start the service first. Navigate to the srv folder.
npm run start
Open another terminal and navigate to app folder. start the approuter.
Open in a New Tab
Our App is running locally from BAS.
After making any changes server.js file, Restart the server.js.
Reference links:
https://developers.sap.com/tutorials/btp-cf-buildpacks-node-create.html