From 4c2f46e2e2dc111b226e929813ee0f3f797987b7 Mon Sep 17 00:00:00 2001 From: Wojciech Stachowski Date: Tue, 12 Aug 2025 11:33:00 +0200 Subject: [PATCH] Allow `upstream` to be `undici.BalancedPool`, pass `maxRetriesOn503` to `replyOpts` --- README.md | 2 ++ index.js | 4 +++- types/index.d.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 154a61d..9820e24 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,8 @@ be streamed directly to the destination._ An URL (including protocol) that represents the target server to use for proxying. +It can be an array of URLs, if you want to use [`undici.BalancedPool`](https://undici.nodejs.org/#/docs/api/BalancedPool) (`upstream` is compatible with [`base`](https://github.com/fastify/fastify-reply-from?tab=readme-ov-file#base) option). + ### `prefix` The prefix to mount this plugin on. All the requests to the current server starting with the given prefix will be proxied to the provided upstream. diff --git a/index.js b/index.js index 10375c9..418e6ab 100644 --- a/index.js +++ b/index.js @@ -532,8 +532,10 @@ async function fastifyHttpProxy (fastify, opts) { const internalRewriteLocationHeader = opts.internalRewriteLocationHeader ?? true const oldRewriteHeaders = (opts.replyOptions || {}).rewriteHeaders + const maxRetriesOn503 = opts.maxRetriesOn503 const replyOpts = Object.assign({}, opts.replyOptions, { - rewriteHeaders + rewriteHeaders, + maxRetriesOn503 }) fromOpts.rewriteHeaders = rewriteHeaders diff --git a/types/index.d.ts b/types/index.d.ts index 7edaac1..acf86ea 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -60,7 +60,7 @@ declare namespace fastifyHttpProxy { ) => string export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions { - upstream: string; + upstream: string | string[]; prefix?: string; rewritePrefix?: string; proxyPayloads?: boolean;