Skip to content

Instantly share code, notes, and snippets.

@wuriyanto48
Created December 5, 2022 07:57
Show Gist options
  • Save wuriyanto48/0029d3e2f5ed8b1bfc6e96ffbe609af4 to your computer and use it in GitHub Desktop.
Save wuriyanto48/0029d3e2f5ed8b1bfc6e96ffbe609af4 to your computer and use it in GitHub Desktop.
axios custom httpAgent with root certificate
const https = require('https');
const axios = require('axios');
const fs = require('fs');
const httpsAgent = new https.Agent({
requestCert: true,
rejectUnauthorized: true,
ca: [fs.readFileSync('./root_cert.pem')],
// cert: [fs.readFileSync('./cert.pem')]
});
const getData = async () => {
try {
const data = await axios({
url: 'https://api-cool.com/v1/people',
method: 'get',
auth: {
username: 'user',
password: '695849d'
},
httpsAgent: httpsAgent
});
console.log(data);
} catch(e) {
console.log('error...');
console.log(e);
}
}
getData();
-----BEGIN CERTIFICATE-----
long certificate
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
short root cert
-----END CERTIFICATE-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment