You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Where <destination-name> is the name of the destination configuration and <path> is the path in the external backend service.
Packaging
The "Destination Proxy" should be packaged by default for the following packages:
sap-cf-all
sap-cf-runtime
sap-kyma-all
sap-kyma-runtime
Enablement
In order to enable the "Destination Proxy" the DIRIGIBLE_DESTINATIONS_PROXY_ENABLED environment variable should be set to true and service binding to the SAP BTP Destination service should should be configured.
Sample code:
constrs=require("http/v4/rs");constbytes=require("io/v4/bytes");consthttpClient=require("http/v4/client");constxml=require("utils/v4/xml");constdestinations=require("core/v4/destinations");constconfig=require("core/v4/configurations");if(config.get("DIRIGIBLE_DESTINATIONS_PROXY_ENABLED","false")!=="true"){thrownewError("Destinations Proxy is disabled");}constIGNORED_HEADERS=["host","accept-encoding","content-length"];rs.service().resource("{destinationName}/{path*}").get(handleGetRequest).put(handlePutRequest).post(handlePostRequest).delete(handleDeleteRequest).execute();functionhandleGetRequest(ctx,request,response){lethttpClientConfig=buildHttpClientConfig(request,ctx.pathParameters.destinationName,ctx.pathParameters.path);letproxyResponse=httpClient.get(httpClientConfig.url,httpClientConfig.options);processProxyResponse(response,proxyResponse);}functionhandlePutRequest(ctx,request,response){lethttpClientConfig=buildHttpClientConfig(request,ctx.pathParameters.destinationName,ctx.pathParameters.path);letproxyResponse=httpClient.put(httpClientConfig.url,httpClientConfig.options);processProxyResponse(response,proxyResponse);}functionhandlePostRequest(ctx,request,response){lethttpClientConfig=buildHttpClientConfig(request,ctx.pathParameters.destinationName,ctx.pathParameters.path);letproxyResponse=httpClient.post(httpClientConfig.url,httpClientConfig.options);processProxyResponse(response,proxyResponse);}functionhandleDeleteRequest(ctx,request,response){lethttpClientConfig=buildHttpClientConfig(request,ctx.pathParameters.destinationName,ctx.pathParameters.path);letproxyResponse=httpClient.delete(httpClientConfig.url,httpClientConfig.options);processProxyResponse(response,proxyResponse);}functionprocessProxyResponse(response,proxyResponse){proxyResponse.headers.forEach(e=>response.setHeader(e.name,e.value));response.setStatus(proxyResponse.statusCode);letdata=proxyResponse.text;if(data===undefined&&proxyResponse.data){data=bytes.byteArrayToText(proxyResponse.data);}response.println(data);}functionbuildHttpClientConfig(request,destinationName,path){letdest=destinations.get(destinationName);letheaders=request.getHeaderNames().filter(e=>!IGNORED_HEADERS.includes(e.toLowerCase())).map(e=>{return{name: e,value: request.getHeader(e)}})if(dest.authTokens&&dest.authTokens[0]){headers.push({name: dest.authTokens[0].http_header.key,value: dest.authTokens[0].http_header.value});}leturl=`${dest.destinationConfiguration.URL}/${path}${request.getQueryString() ? "?"+request.getQueryString() : ""}`;lethttpClientConfig={url: url,options: {headers: headers,text: getPayload(request),contentType: getContentType(headers)}};setHttpClientConfigContentType(httpClientConfig);returnhttpClientConfig;}functionsetHttpClientConfigContentType(httpClientConfig){if(!httpClientConfig.options.contentType&&httpClientConfig.options.text){try{JSON.parse(httpClientConfig.options.text);httpClientConfig.options.contentType="application/json";return;}catch(e){// Do nothing}try{xml.toJson(httpClientConfig.options.text)httpClientConfig.options.contentType="application/xml";return;}catch(e){// Do nothing}httpClientConfig.options.contentType="plain/text";}}functiongetPayload(request){letpayload=request.getText();if(payload){returnpayload;}}functiongetContentType(headers){if(headers){for(leti=0;i<headers.length;i++){if(headers[i].name.toLowerCase()==="content-type"){returnheaders[i].value;}}}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Introduce backend proxy (based on destination configuration) for the SAP BTP Kyma and SAP BTP Cloud Foundry environments.
The goal is to be able to perform HTTP calls from app UI (running in the same Dirigible instance) to external backend services (cloud or on-prem).
Sample endpoint:
Where
<destination-name>
is the name of the destination configuration and<path>
is the path in the external backend service.Packaging
The "Destination Proxy" should be packaged by default for the following packages:
Enablement
In order to enable the "Destination Proxy" the
DIRIGIBLE_DESTINATIONS_PROXY_ENABLED
environment variable should be set totrue
and service binding to the SAP BTP Destination service should should be configured.Sample code:
Beta Was this translation helpful? Give feedback.
All reactions