Skip to content

Commit

Permalink
fix(core): share request config across all requests (#928)
Browse files Browse the repository at this point in the history
* fix added by bumping core to 0.3.5
* this will allow users to configure all requests, which fixes a bug that prevented use of the SDK behind a corporate proxy
* documentation added for this use case in the readme
  • Loading branch information
dpopp07 authored Aug 7, 2019
1 parent 1a751dd commit 7fd5577
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Node.js client library to use the Watson APIs.
* [Sending request headers](#sending-request-headers)
* [Parsing HTTP response](#parsing-http-response)
* [Data collection opt-out](#data-collection-opt-out)
* [Using the SDK behind a corporate proxy](#using-the-sdk-behind-a-corporate-proxy)
* [Documentation](#documentation)
* [Questions](#questions)
* [IBM Watson services](#ibm-watson-services)
Expand Down Expand Up @@ -266,18 +267,6 @@ discovery.listEnvironments((err, res) => {
});
```

### Setting the service URL

You can set the service URL by calling the setServiceUrl() method.

```javascript
const discovery = new DiscoveryV1({
version: '<version-date>'
});

discovery.setServiceUrl('https://gateway-wdc.watsonplatform.net/discovery/api');
```

### Sending request headers

Custom headers can be passed with any request. Each method has an optional parameter `headers` which can be used to pass in these custom headers, which can override headers that we use as parameters.
Expand Down Expand Up @@ -352,6 +341,24 @@ var myInstance = new watson.WhateverServiceV1({
});
```
### Using the SDK behind a corporate proxy
To use the SDK (which makes HTTPS requests) behind an HTTP proxy, a special tunneling agent must be used. Use the package [`tunnel`](https://github.com/koichik/node-tunnel/) for this. Configure this agent with your proxy information, and pass it in as the HTTPS agent in the service constructor. Additionally, you must set `proxy` to `false` in the service constructor. See this example configuration:
```js
const tunnel = require('tunnel');
const AssistantV1 = require('ibm-watson/assistant/v1');

const assistant = new AssistantV1({
iam_apikey: 'fakekey1234',
version: '2019-02-28',
httpsAgent: tunnel.httpsOverHttp({
host: 'some.host.org',
port: 1234,
}),
proxy: false,
});
```
### Configuring the HTTP client
The HTTP client can be configured to disable SSL verification. Note that this has serious security implications - only do this if you really mean to! ⚠️
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"axios": "^0.18.0",
"dotenv": "^6.2.0",
"extend": "~3.0.2",
"ibm-cloud-sdk-core": "^0.3.4",
"ibm-cloud-sdk-core": "^0.3.5",
"isstream": "~0.1.2",
"object.pick": "~1.3.0",
"snyk": "^1.192.4",
Expand Down

0 comments on commit 7fd5577

Please sign in to comment.