Skip to content

Commit 36c6921

Browse files
ericfichteleric-fichtel-adobeXDex
authored
TNT-46700 Adding documentation and samples for proxy configuration (#53)
* sample for adding a proxy to the node sdk http calls * Small typo fix Co-authored-by: Andrei Anischevici <[email protected]> --------- Co-authored-by: Eric Fichtel <[email protected]> Co-authored-by: Andrei Anischevici <[email protected]>
1 parent 93c312f commit 36c6921

File tree

7 files changed

+1618
-0
lines changed

7 files changed

+1618
-0
lines changed

proxy-configuration/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Proxy Configuration Sample
2+
3+
## Overview
4+
5+
It is possible to configure a proxy for the Node SDK's HTTP requests. This is possible by overriding the `fetch` API used by the SDK during initialization.
6+
7+
This sample contains three different code snippets that demonstrate how to configure the SDK with a proxy, depending on which Node version the SDK runs on:
8+
9+
- [Node 18.2+](proxy-sample-node-18.js) (`undici.fetch` is the default `fetch`)
10+
- [Node 16.8+](proxy-sample-node-16.js) (`undici.fetch` needs to be imported)
11+
- [Node 14+](proxy-sample-node-14.js) (the proxy is configured with `node-fetch`)
12+
13+
The difference in proxy configurations is due to differences in the fetch implementations between Node versions.
14+
Starting with Node 18.2, the default implementation of `fetch` switched to `undici.fetch`.
15+
However, `unidici.fetch` is only supported in Node 16.8+. Users are welcome to choose their own `fetch` and proxy client configurations.
16+
These samples only serve as guidance for those considering adding a proxy to their SDK HTTP calls.
17+
18+
## Usage
19+
20+
1. `npm start` to start a local proxy server
21+
2. in a separate window, run `node proxy-sample-node-[version]` to initialize a sample Target Client and make a `getOffers` call with a proxy configured
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
const { createProxyServer } = require("@mutagen-d/node-proxy-server");
3+
4+
const port = 8080;
5+
const server = createProxyServer();
6+
7+
server.on("error", error => {
8+
console.log("server error", error);
9+
});
10+
11+
server.on("connection", conn => {
12+
console.log("Successfully connected", conn);
13+
});
14+
15+
server.listen(port, "0.0.0.0", () =>
16+
console.log("proxy-server listening port", port)
17+
);

0 commit comments

Comments
 (0)