Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/api-requestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ module.exports = class ApiRequestor {
reqOpts.port = this._chargehound.options.port
}

if (this._chargehound.options.protocol === 'https://') {
req = https.request(reqOpts).setTimeout(this.getTimeout())
connectEv = 'secureConnect'
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not see if the env is local or not and then use the protocol based on that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (this._chargehound.options.env != null && this._chargehound.options.env === 'local') {
req = http.request(reqOpts).setTimeout(this.getTimeout())
connectEv = 'connect'
} else {
req = https.request(reqOpts).setTimeout(this.getTimeout())
connectEv = 'secureConnect'
}

req.on('timeout', function () {
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const CHARGEHOUND_PROTOCOL = 'https://'
const CHARGEHOUND_HOST = 'api.chargehound.com'
const CHARGEHOUND_BASE_PATH = '/v1/'
const CHARGEHOUND_TIMEOUT = 60 * 1000
const CHARGEHOUND_ENV = null

function Chargehound (apiKey, options) {
if (!(this instanceof Chargehound)) {
Expand All @@ -27,6 +28,7 @@ function Chargehound (apiKey, options) {
port: options.port || null,
protocol: options.protocol || CHARGEHOUND_PROTOCOL,
timeout: options.timeout || CHARGEHOUND_TIMEOUT,
env: options.env || CHARGEHOUND_ENV,
version: options.version || null
}

Expand Down