Skip to content

Commit

Permalink
Update outbound snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Malogulko committed Feb 17, 2021
1 parent d3a11b1 commit f3c33be
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions content-by-language/node/outbound-integration.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
const fs = require('fs');
const url = require('url');
const fetch = require('node-fetch');
const HttpsProxyAgent = require('https-proxy-agent');
const urlParams = url.parse('http://{ACCESS_CREDENTIALS}@{VAULT_HOST}:{PORT}');
const agent = new HttpsProxyAgent({
...urlParams,
ca: [fs.readFileSync('{CERT_LOCATION}')],
});
const request = require('axios');
const tunnel = require('tunnel');

async function getData() {
let result;
try {
result = await fetch('{VGS_SAMPLE_ECHO_SERVER}/post', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
account_number: '{ALIAS}',
}),
agent,
});
} catch (e) {
console.error(e);
}
return await result.text();
const tunnelingAgent = tunnel.httpsOverHttp({
ca: [ fs.readFileSync('{CERT_LOCATION}')],
proxy: {
host: '{VAULT_HOST}',
port: '{PORT}',
proxyAuth: '{ACCESS_CREDENTIALS}'
}
});

const redactedPayload = {
account_number: '{ALIAS}',
};

return await request.post(
'{VGS_SAMPLE_ECHO_SERVER}/post',
JSON.stringify(redactedPayload),
{
httpsAgent: tunnelingAgent,
proxy: false,
headers: {
'Content-Type':'application/json'
}
}).then((r) => {
console.log('\\nResponse from Axios request on REVEAL:');
console.log(r.data);
return r.data;
});
}

getData().then(response => console.log(response));

0 comments on commit f3c33be

Please sign in to comment.