Skip to content

Commit c5b7e84

Browse files
authored
Merge pull request #5134 from segmentio/update-segment-node
Update analytics-node
2 parents 4c62008 + fce4d0c commit c5b7e84

File tree

1 file changed

+18
-16
lines changed
  • src/connections/sources/catalog/libraries/server/node

1 file changed

+18
-16
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ Setting | Details
282282
`maxRetries` _number_ | The number of times to retry flushing a batch. The default is: `3`
283283
`maxEventsInBatch` _number_ | The number of messages to enqueue before flushing. The default is: `15`
284284
`flushInterval` _number_ | The number of milliseconds to wait before flushing the queue automatically. The default is: `10000`
285-
`httpRequestTimeout` | The maximum number of milliseconds to wait for an http request. The default is: `10000`
286-
`disable` | Disable the analytics library for testing. The default is: `false`
287-
`httpClient` *Optional* | A custom AnalyticsHTTPClient implementation to support alternate libraries or proxies. Defaults to global fetch or node-fetch for older versions of node.
285+
`httpRequestTimeout` _number_ | The maximum number of milliseconds to wait for an http request. The default is: `10000`
286+
`disable` _boolean_ | Disable the analytics library for testing. The default is: `false`
287+
`httpClient` _HTTPClient or HTTPClientFn_ | A custom HTTP Client implementation to support alternate libraries or proxies. Defaults to global fetch or node-fetch for older versions of node. See the [Overriding the default HTTP Client](#override-the-default-http-client) section for more details.
288+
289+
See the complete `AnalyticsSettings` interface [here](https://github.com/segmentio/analytics-next/blob/master/packages/node/src/app/settings.ts){:target="_blank"}.
288290
289291
## Graceful shutdown
290292
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.
@@ -554,7 +556,7 @@ Different parts of your application may require different types of batching, or
554556
const marketingAnalytics = new Analytics({ writeKey: 'MARKETING_WRITE_KEY' });
555557
const appAnalytics = new Analytics({ writeKey: 'APP_WRITE_KEY' });
556558
```
557-
## AnalyticsHTTPClient
559+
## Override the default HTTP Client
558560
559561
Segment attempts to use the global `fetch` implementation if available in order to support several diverse environments. Some special cases (for example, http proxy) may require a different implementation for http communication. You can provide a customized wrapper in the Analytics configuration to support this. Here are a few approaches:
560562
@@ -563,21 +565,21 @@ Use a custom fetch-like implementation with proxy (simple, recommended)
563565
import { HTTPFetchFn } from '../lib/http-client'
564566
import axios from 'axios'
565567
566-
const httpClient: HTTPFetchFn = async (url, options) => {
567-
return axios({
568+
const httpClient: HTTPFetchFn = async (url, { body, ...options }) =>
569+
axios({
568570
url,
571+
data: body,
569572
proxy: {
570-
protocol: 'http',
571-
host: 'proxy.example.com',
572-
port: 8886,
573-
auth: {
574-
username: 'user',
575-
password: 'pass',
576-
},
573+
protocol: 'http',
574+
host: 'proxy.example.com',
575+
port: 8886,
576+
auth: {
577+
username: 'user',
578+
password: 'pass',
577579
},
580+
},
578581
...options,
579582
})
580-
}
581583
582584
const analytics = new Analytics({
583585
writeKey: '<YOUR_WRITE_KEY>',
@@ -591,8 +593,8 @@ import { FetchHTTPClient, HTTPClientRequest } from '@segment/analytics-node'
591593
class MyClient extends FetchHTTPClient {
592594
async makeRequest(options: HTTPClientRequest) {
593595
return super.makeRequest({
594-
...options,
595-
headers: { ...options.headers, foo: 'bar' }
596+
...options,
597+
headers: { ...options.headers, foo: 'bar' }
596598
}})
597599
}
598600
}

0 commit comments

Comments
 (0)