We are using Cloud SDk library ->@sap-cloud-sdk/http-client - npm (npmjs.com) and it function executeHttpRequest to send request to convergent mediation system(On premise ) via cloud connector .The connectivity is made using Destination which is mainatained in BTP subaccount.
Issue : when we send request to Microservice on particular endpoint. Cloud connector logs shows three requests being fired at the same time even though we send the request once.
const { executeHttpRequest } = require('@sap-cloud-sdk/http-client');
const express = require('express'); const app = express();
app.use(express.json());
app.post('/xyz', async (req, res) => {
try {
async function callPostApi(req, destination) {
const response = await executeHttpRequest(
{
destinationName: destination,
},
{
method: 'POST',
url: req.url,
data: req.body,
maxContentLength: Infinity,
maxBodyLength: Infinity,
headers: {
"Content-Type": "application/json"
},
}
);
return response.data;
}
const responseData = await callPostApi(req, "Destination Name");
res.status(200).send(responseData);
} catch (error) {
console.error('Error:', error);
res.status(500).send({ message: "An error occurred", error });
} });
The reason is that SDK makes additional calls to fetch CSRF tokens by default for POST requests. This can be turned off by setting:
{
fetchCsrfToken: false
}
as the 3rd parameter of the executeHttpRequest
function. Further documentation can be found here