mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
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:
@@ -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}`);
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user