-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
18 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
module.exports = function (name) { | ||
const certFile = path.resolve(__dirname, `${name}_cert.pem`); | ||
const keyFile = path.resolve(__dirname, `${name}_key.pem`); | ||
return new https.Agent({ | ||
cert: fs.readFileSync(certFile), | ||
key: fs.readFileSync(keyFile), | ||
rejectUnauthorized: false | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,13 @@ | ||
const axios = require('axios'); | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const agent = require('./agent'); | ||
|
||
const serverUrl = 'https://localhost:4433/authenticate'; | ||
let opts = { httpsAgent: agent('bob') }; | ||
|
||
// Configure certifcate options | ||
const certFile = path.resolve(__dirname, 'bob_cert.pem'); | ||
const keyFile = path.resolve(__dirname, 'bob_key.pem'); | ||
let agent = new https.Agent({ | ||
cert: fs.readFileSync(certFile), | ||
key: fs.readFileSync(keyFile), | ||
rejectUnauthorized: false | ||
}); | ||
let opts = { httpsAgent: agent }; | ||
|
||
// Test with Promises | ||
axios.get(serverUrl, opts) | ||
.then((res) => { | ||
console.log(res.data); | ||
}) | ||
.catch((err) => { | ||
console.error(err.response.data); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,13 @@ | ||
const axios = require('axios'); | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const agent = require('./agent'); | ||
|
||
const serverUrl = 'https://localhost:4433/authenticate'; | ||
let opts = { httpsAgent: agent('alice') }; | ||
|
||
// Configure certifcate options | ||
const certFile = path.resolve(__dirname, 'alice_cert.pem'); | ||
const keyFile = path.resolve(__dirname, 'alice_key.pem'); | ||
let agent = new https.Agent({ | ||
cert: fs.readFileSync(certFile), | ||
key: fs.readFileSync(keyFile), | ||
rejectUnauthorized: false | ||
}); | ||
let opts = { httpsAgent: agent }; | ||
|
||
// Test with Promises | ||
axios.get(serverUrl, opts) | ||
.then((res) => { | ||
console.log(res.data); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
console.error(err.response.data); | ||
}); | ||
|
||
// Test with async/away | ||
async function testClient() { | ||
try { | ||
const res = await axios.get(serverUrl, opts); | ||
console.log(res.data); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
// testClient(); |