diff --git a/docs/helpers/REST.md b/docs/helpers/REST.md index 953208444..d35e8ff20 100644 --- a/docs/helpers/REST.md +++ b/docs/helpers/REST.md @@ -69,6 +69,22 @@ Type: [object][4] } ``` +```js +{ + helpers: { + REST: { + endpoint: 'http://site.com/api', + prettyPrintJson: true, + httpAgent: { + ca: fs.readFileSync(__dirname + '/path/to/ca.pem'), + rejectUnauthorized: false, + keepAlive: true + } + } + } +} +``` + ## Access From Helpers Send REST requests by accessing `_executeRequest` method: diff --git a/lib/helper/REST.js b/lib/helper/REST.js index bd79b2ce6..4d36be1d9 100644 --- a/lib/helper/REST.js +++ b/lib/helper/REST.js @@ -63,6 +63,22 @@ const config = {} * } * ``` * + * ```js + * { + * helpers: { + * REST: { + * endpoint: 'http://site.com/api', + * prettyPrintJson: true, + * httpAgent: { + * ca: fs.readFileSync(__dirname + '/path/to/ca.pem'), + * rejectUnauthorized: false, + * keepAlive: true + * } + * } + * } + * } + * ``` + * * ## Access From Helpers * * Send REST requests by accessing `_executeRequest` method: @@ -101,9 +117,13 @@ class REST extends Helper { // Create an agent with SSL certificate if (this.options.httpAgent) { - if (!this.options.httpAgent.key || !this.options.httpAgent.cert) + // if one of those keys is there, all good to go + if (this.options.httpAgent.ca || this.options.httpAgent.key || this.options.httpAgent.cert) { + this.httpsAgent = new Agent(this.options.httpAgent) + } else { + // otherwise, throws an error of httpAgent config throw Error('Please recheck your httpAgent config!') - this.httpsAgent = new Agent(this.options.httpAgent) + } } this.axios = this.httpsAgent ? axios.create({ httpsAgent: this.httpsAgent }) : axios.create()