{
"name": "<APP_NAME>",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Prashant Patil",
"license": "ISC",
"dependencies": {
"@sap/xsenv": "^2.2.0",
"body-parser": "^1.19.0",
"express": "^4.16.4",
"request": "^2.88.0",
"request-promise": "^4.2.5"
}
}
---
applications:
- name: test-app
memory: 128M
instances: 1
services:
- test-app-uaa
- test-app-conn
cf create-service xsuaa application test-app-uaa
cf create-service connectivity lite test-app-conn
const express = require('express');
const rp = require('request-promise');
const xsenv = require('@sap/xsenv');
//For local run
//xsenv.loadEnv();
const http = require('http');
var bodyParser = require('body-parser');
const app = express();
var server = http.createServer(app);
const port = process.env.PORT || 3000;
var jsonParser = bodyParser.json();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
const conn_service = xsenv.getServices({ conn: { tag: 'connectivity' } }).conn;
const uaa_service = xsenv.getServices({ uaa: { tag: 'xsuaa' } }).uaa;
const sUaaCredentials = conn_service.clientid + ':' + conn_service.clientsecret;
const proxy_url = 'http://'+conn_service["onpremise_proxy_host"] + ':' + conn_service["onpremise_proxy_port"];
const onPremCred = '<OnpremSrvUser>:<OnpremSrvUserPassword>';
server.listen(port, () => console.log(`test app listening at http://localhost:${port}`));
app.post('/getDetailsFromOnPrem',jsonParser , (req, res) => {
return rp({
uri: uaa_service.url + '/oauth/token',
method: 'POST',
headers: {
'Authorization': 'Basic ' + Buffer.from(sUaaCredentials).toString('base64'),
'Content-type': 'application/x-www-form-urlencoded'
},
form: {
'client_id': conn_service.clientid,
'grant_type': 'client_credentials'
}
}).then((data) => {
const token = JSON.parse(data).access_token;
return rp({
uri: '<on-prem service url>',
proxy:proxy_url,
headers : {
'Authorization': 'Basic ' + Buffer.from(onPremCred).toString('base64'),
'Proxy-Authorization': 'Bearer ' + token,
'SAP-Connectivity-SCC-Location_ID':'<Cloud-Connector-Location-Id>',
'Content-type': 'application/json'
}
});
}).then((data) => {
const d = JSON.parse(data);
res.send(d);
}).catch((error) => {
res.send(error);
});
cf push test-app
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |