From 7fd557726de7899ce508081301c32327ba4ba3d3 Mon Sep 17 00:00:00 2001 From: Dustin Popp Date: Wed, 7 Aug 2019 17:06:08 -0500 Subject: [PATCH] fix(core): share request config across all requests (#928) * 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 --- README.md | 31 +++++++++++++++++++------------ package-lock.json | 6 +++--- package.json | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2ae5818ab6..76fd6b92ed 100755 --- a/README.md +++ b/README.md @@ -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) @@ -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: '' -}); - -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. @@ -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! ⚠️ diff --git a/package-lock.json b/package-lock.json index 0dcc3ff00f..49c31d444e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5237,9 +5237,9 @@ } }, "ibm-cloud-sdk-core": { - "version": "0.3.4", - "resolved": "https://registry.npmjs.org/ibm-cloud-sdk-core/-/ibm-cloud-sdk-core-0.3.4.tgz", - "integrity": "sha512-d+2YW5PnQ9CrrJc7tiyIhFMs/ufgtpvLIqQMhL6Pxde6hCMtpO1NwsJ5UusKybTJx6+ScscKLPtRcDbh8/anKA==", + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/ibm-cloud-sdk-core/-/ibm-cloud-sdk-core-0.3.5.tgz", + "integrity": "sha512-hTnebYS/uC5VGvTHnwSPc20LFfz3EiuXGV+gnIrd5KgjKM6PDp/YRBGAKduwyj9BJD6saqVyPCiWcxK0gZEsBQ==", "requires": { "@types/extend": "~3.0.0", "@types/file-type": "~5.2.1", diff --git a/package.json b/package.json index 3acf4efeec..3b4c503872 100644 --- a/package.json +++ b/package.json @@ -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",