Initial commit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
谢宇宁
2026-10-26 17:51:31 +07:00
co-authored by Claude Opus 5.5
commit 61d0a11dfa
371 changed files with 35836 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
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;