fix(proxy): use undici fetch to resolve Node 22 incompatibility with proxyDispatcher (#1056)

test: update login-bootstrap-route metadata assertions
This commit is contained in:
diegosouzapw
2026-04-08 03:45:27 -03:00
parent e1df1e7350
commit 4af7a1896c
2 changed files with 10 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import { AsyncLocalStorage } from "node:async_hooks";
import { fetch as undiciFetch } from "undici";
import {
createProxyDispatcher,
getDefaultDispatcher,
@@ -164,7 +165,7 @@ export async function runWithProxyContext(proxyConfig, fn) {
async function patchedFetch(input: RequestInfo | URL, options: FetchWithDispatcherOptions = {}) {
if (options?.dispatcher) {
return originalFetchWithDispatcher(input, options);
return (undiciFetch as any)(input, options);
}
const targetUrl = getTargetUrl(input);
@@ -197,7 +198,7 @@ async function patchedFetch(input: RequestInfo | URL, options: FetchWithDispatch
if (store) store.used = false;
}
}
return originalFetchWithDispatcher(input, {
return (undiciFetch as any)(input, {
...options,
dispatcher: getDefaultDispatcher(),
});
@@ -205,7 +206,7 @@ async function patchedFetch(input: RequestInfo | URL, options: FetchWithDispatch
try {
const dispatcher = createProxyDispatcher(proxyUrl);
return await originalFetchWithDispatcher(input, { ...options, dispatcher });
return await (undiciFetch as any)(input, { ...options, dispatcher });
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.error(`[ProxyFetch] Proxy request failed (${source}, fail-closed): ${message}`);

View File

@@ -49,6 +49,8 @@ test("public login bootstrap route exposes the metadata the login page consumes"
requireLogin: true,
hasPassword: false,
setupComplete: true,
nodeVersion: body.nodeVersion,
nodeCompatible: body.nodeCompatible,
});
});
@@ -68,6 +70,8 @@ test("public login bootstrap route reports env-provided bootstrap password metad
requireLogin: true,
hasPassword: true,
setupComplete: true,
nodeVersion: body.nodeVersion,
nodeCompatible: body.nodeCompatible,
});
});
@@ -86,6 +90,8 @@ test("public login bootstrap route reports stored password metadata and disabled
requireLogin: false,
hasPassword: true,
setupComplete: true,
nodeVersion: body.nodeVersion,
nodeCompatible: body.nodeCompatible,
});
});