Skip to content

Commit 8104d33

Browse files
authored
Adding info about new http client
1 parent fbd224a commit 8104d33

File tree

1 file changed

+38
-0
lines changed
  • src/connections/sources/catalog/libraries/server/node

1 file changed

+38
-0
lines changed

src/connections/sources/catalog/libraries/server/node/index.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ Setting | Details
284284
`flushInterval` _number_ | The number of milliseconds to wait before flushing the queue automatically. The default is: `10000`
285285
`httpRequestTimeout` | The maximum number of milliseconds to wait for an http request. The default is: `10000`
286286
`disable` | Disable the analytics library for testing. The default is: `false`
287+
`httpClient` | Optional custom AnalyticsHTTPClient implementation to support alternate libraries or proxies. Defaults to global fetch or node-fetch for older versions of node.
287288
288289
## Graceful shutdown
289290
Avoid losing events after shutting down your console. Call `.closeAndFlush()` to stop collecting new events and flush all existing events. If a callback on an event call is included, this also waits for all callbacks to be called, and any of their subsequent promises to be resolved.
@@ -553,7 +554,44 @@ Different parts of your application may require different types of batching, or
553554
const marketingAnalytics = new Analytics({ writeKey: 'MARKETING_WRITE_KEY' });
554555
const appAnalytics = new Analytics({ writeKey: 'APP_WRITE_KEY' });
555556
```
557+
## AnalyticsHTTPClient
556558
559+
In some cases such as supporting an environment with an http proxy in place, you may need to use something other than our multiplatform `fetch` call. You can create a custom `AnalyticsHTTPClient` implementation and pass it in to the Analytics Configuration.
560+
561+
An example of supporting proxies with a popular library, axios:
562+
```javascript
563+
const axios = require('axios')
564+
565+
export class ProxyAxiosClient implements AnalyticsHTTPClient {
566+
public proxy = null
567+
async send(
568+
url: string,
569+
options: AnalyticsHTTPClientOptions
570+
): Promise<AnalyticsHTTPClientResponse> {
571+
const proxyoptions = Object.assign({}, options, this.proxy)
572+
return await axios.get(url, proxyoptions)
573+
}
574+
}
575+
```
576+
And then in your initialization:
577+
```javascript
578+
const proxyHttpClient = new ProxyAxiosClient()
579+
proxyHttpClient.proxy = {
580+
proxy: {
581+
protocol: 'http',
582+
host: 'proxy.example.com',
583+
port: 8886,
584+
auth: {
585+
username: 'user',
586+
password: 'pass',
587+
},
588+
},
589+
}
590+
const analytics = new Analytics({
591+
writeKey: '<YOUR_WRITE_KEY>',
592+
httpClient: proxyHttpClient,
593+
})
594+
```
557595
558596
## Troubleshooting
559597

0 commit comments

Comments
 (0)