Files
web_hghl_h5/src/instrumentation-node.ts
T
谢宇宁andClaude Opus 5.5 61d0a11dfa Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:51:31 +07:00

33 lines
1.0 KiB
TypeScript

import dns from "node:dns";
/**
* Node-only:强制优先 / 仅用 IPv4,避免 Cloudflare AAAA ENETUNREACH
* 与 Happy Eyeballs 并行试 IPv6 时刷 AggregateError。
*/
dns.setDefaultResultOrder("ipv4first");
const nativeLookup = dns.lookup.bind(dns) as (
hostname: string,
options?: unknown,
callback?: unknown,
) => unknown;
// dns.lookup 重载签名在不同 @types/node 版本间不一致,这里按运行时重载包装。
dns.lookup = ((hostname: string, options?: unknown, callback?: unknown) => {
if (typeof options === "function") {
return nativeLookup(hostname, { family: 4 }, options);
}
if (typeof callback === "function") {
const opts =
typeof options === "number"
? { family: 4 }
: { ...(options as object | undefined), family: 4 };
return nativeLookup(hostname, opts, callback);
}
const opts =
typeof options === "number"
? { family: 4 }
: { ...(options as object | undefined), family: 4 };
return nativeLookup(hostname, opts);
}) as typeof dns.lookup;