Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Consuming Odata from Nodejs in Cloudfoundry not working

Badhusha
Participant
0 Likes
1,725

Hi,

I am developing a nodejs application, which fetches data from an on-premise OData service and returns it back as a response. This is my node js application's code.

server.js

var http = require('http');
var express = require('express')
var request= require('request')
const bodyParser = require('body-parser')
const turl = require('turl')
var app = express()
const port =process.env.PORT ||3000
app.use(bodyParser.json())
app.use(express.static(__dirname));
var url ='http://10.124.2.117:8000/sap/opu/odata/sap/ZGW_EMPLOYEE_INFO_SRV/EmployeeHeaderSet';
app.get('/',async(req,res)=>{
var headers={
'Content-Type':'application/json',
'Accept':'application/json',
'Authorization':'Basic YmFkaHKzaGE6YWlodGhhPXI=',
"x-csrf-token" : "Fetch"};
var options={
          method:'GET',
          url: url,
          headers:headers
            };

request(options,function(error, response, body){
if(!error && response.statusCode ==200){
    var resultData = JSON.parse(body);//Process the dataandreturn the response
}
else{
console.log("Error happened");
    }
    });
});
app.listen(port,()=>{ 
    console.log('Server is running on port '+port)})
<br>
<br>

manifest.yaml

---
applications:-name: myapp
  random-route: true
  path: myapp
  memory:128M
  health-check-type:none
  services:- myuaa

xs-app.json

{"xsappname" : "myapp","tenant-mode" : "dedicated"}

When I run this application on the local system it is returning the response as expected, but when I deploy this node js application to the Cloudfoundry Environment, it is showing "Error happened".

Is there any other way to consume the data ?

What is the problem with my code?

Thanks in advance

Note: I am using TM System

1 ACCEPTED SOLUTION
Read only

pfefferf
Active Contributor
1,245

As the system you are trying to call is not available in public, the request fails of course when it is executed in the CF environment.

You have to use the Connectivity service to access your on-premise system via SAP Cloud Connector. For details please check the online documentation: Consuming the Connectivity Service

Hi,

I am developing a nodejs application, which fetches data from an on-premise OData service and returns it back as a response. This is my node js application's code.

server.js

var http = require('http');
var express = require('express')
var request= require('request')
const bodyParser = require('body-parser')
const turl = require('turl')
var app = express()
const port =process.env.PORT ||3000
app.use(bodyParser.json())
app.use(express.static(__dirname));
var url ='http://10.124.2.117:8000/sap/opu/odata/sap/ZGW_EMPLOYEE_INFO_SRV/EmployeeHeaderSet';
app.get('/',async(req,res)=>{
var headers={
'Content-Type':'application/json',
'Accept':'application/json',
'Authorization':'Basic YmFkaHKzaGE6YWlodGhhPXI=',
"x-csrf-token" : "Fetch"};
var options={
          method:'GET',
          url: url,
          headers:headers
            };

request(options,function(error, response, body){
if(!error && response.statusCode ==200){
    var resultData = JSON.parse(body);//Process the dataandreturn the response
}
else{
console.log("Error happened");
    }
    });
});
app.listen(port,()=>{ 
    console.log('Server is running on port '+port)})
<br>
<br>

manifest.yaml

---
applications:-name: myapp
  random-route: true
  path: myapp
  memory:128M
  health-check-type:none
  services:- myuaa

xs-app.json

{"xsappname" : "myapp","tenant-mode" : "dedicated"}

When I run this application on the local system it is returning the response as expected, but when I deploy this node js application to the Cloudfoundry Environment, it is showing "Error happened".

Is there any other way to consume the data ?

What is the problem with my code?

Thanks in advance

Note: I am using TM System

3 REPLIES 3
Read only

pfefferf
Active Contributor
1,246

As the system you are trying to call is not available in public, the request fails of course when it is executed in the CF environment.

You have to use the Connectivity service to access your on-premise system via SAP Cloud Connector. For details please check the online documentation: Consuming the Connectivity Service

Read only

0 Likes
1,245

Hi Florian,

Is there any other blog which depicts the same, as you have mentioned in link.

Read only

pfefferf
Active Contributor
0 Likes
1,245

Just a simple search here in the community brings up a lot of results. For instance https://blogs.sap.com/2017/07/09/how-to-use-the-sap-cloud-platform-connectivity-and-the-cloud-connec...