Skip to content

Commit e776e7b

Browse files
author
vhess
committed
rename customFetch to fetch and address some documentation errors
1 parent a13d600 commit e776e7b

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ import { Agent } from "undici";
268268
// Create a proxy server with fetch and HTTP/2 support
269269
const proxy = createProxyServer({
270270
target: "https://127.0.0.1:5050",
271-
fetch: {
271+
fetchOptions: {
272272
requestOptions: {dispatcher: new Agent({ allowH2: true })},
273273
// Modify the request before it's sent
274274
onBeforeRequest: async (requestOptions, req, res, options) => {
@@ -472,7 +472,7 @@ const proxy = createProxyServer({
472472
// Shorthand to enable fetch with defaults
473473
const proxy = createProxyServer({
474474
target: "https://http2-server.example.com",
475-
fetch: true // Uses default fetch configuration
475+
fetch // Uses default fetch configuration
476476
});
477477
```
478478

@@ -482,7 +482,7 @@ const proxy = createProxyServer({
482482
const proxy = createProxyServer({
483483
target: "https://api.example.com",
484484
fetchOptions: {
485-
requestOptions: {
485+
requestOptions: {
486486
// Use undici's Agent for HTTP/2 support
487487
dispatcher: new Agent({
488488
allowH2: true,
@@ -524,13 +524,14 @@ const proxy = createProxyServer({
524524
key: readFileSync("server-key.pem"),
525525
cert: readFileSync("server-cert.pem")
526526
},
527-
fetch: {
528-
dispatcher: new Agent({
529-
allowH2: true,
530-
connect: { rejectUnauthorized: false }
531-
})
527+
fetchOptions: {
528+
requestOptions: {
529+
dispatcher: new Agent({
530+
allowH2: true,
531+
connect: { rejectUnauthorized: false }
532+
})
533+
}
532534
},
533-
secure: false // Skip SSL verification for self-signed certs
534535
}).listen(8443);
535536
```
536537

@@ -757,8 +758,8 @@ import { Agent } from "undici";
757758

758759
const proxy = createProxyServer({
759760
target: "https://api.example.com",
760-
fetch: {
761-
dispatcher: new Agent({ allowH2: true }),
761+
fetchOptions: {
762+
requestOptions: {dispatcher: new Agent({ allowH2: true })},
762763
// Called before making the fetch request
763764
onBeforeRequest: async (requestOptions, req, res, options) => {
764765
// Modify the outgoing request

lib/http-proxy/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export interface ServerOptions {
9898
*/
9999
ca?: string;
100100
/** Enable using fetch for proxy requests. Set to true for defaults, or provide custom configuration. */
101-
fetchOptions?: boolean | FetchOptions;
102-
customFetch?: typeof fetch;
101+
fetchOptions?: FetchOptions;
102+
fetch?: typeof fetch;
103103
}
104104
export interface FetchOptions {
105105
/** Fetch request options */

lib/http-proxy/passes/web-incoming.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function stream(
8686
// And we begin!
8787
server.emit("start", req, res, options.target || options.forward!);
8888

89-
if (options.fetchOptions || process.env.FORCE_FETCH_PATH === "true") {
89+
if (options.fetch ||options.fetchOptions || process.env.FORCE_FETCH_PATH === "true") {
9090
return stream2(req, res, options, _, server, cb);
9191
}
9292

lib/test/http/customFetch.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ describe("Basic example of proxying over HTTP2 to a target HTTP2 with custom Fet
4848
.createServer({
4949
target: `https://localhost:${ports.http2}`,
5050
ssl,
51-
customFetch: customFetch,
52-
fetchOptions: true,
51+
fetch: customFetch,
5352
})
5453
.listen(ports.proxy);
5554
});

0 commit comments

Comments
 (0)