feat: add proxy DNS resolver and reorder defaults#32
Conversation
Adds proxyDnsResolver targeting https://dns.opencerts.io/resolve, a server-side DoH proxy that forwards to Google/Cloudflare upstream. Useful as a fallback in regions where direct Google/Cloudflare DoH access is blocked. Moves aliDnsResolver to the end of the fallback chain because it truncates large TXT responses (verified live against example.tradetrust.io: Ali returned 11 of 58 records while Google, Cloudflare, and the proxy each returned all 58). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughA new DNS-over-HTTPS proxy resolver ( ChangesProxy DNS Resolver Addition
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/index.ts (1)
27-32: ⚡ Quick winConsider a contract test for default resolver order.
Since this PR intentionally changes fallback order, add one focused test that asserts
defaultDnsResolverssequence to prevent accidental reordering in future refactors.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/index.ts` around lines 27 - 32, Add a focused contract test that asserts the exact order of the exported defaultDnsResolvers array to prevent accidental reorderings: write a unit test that imports defaultDnsResolvers and verifies its sequence equals [googleDnsResolver, cloudflareDnsResolver, proxyDnsResolver, aliDnsResolver] (or compares names/identifiers if direct object equality is brittle); name the test to indicate it guards resolver fallback order and keep it small and isolated so future refactors will fail if the order changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/util/dns-resolvers/proxy-dns-resolver.ts`:
- Around line 7-9: The current validation only checks falsy values so
whitespace-only strings pass; trim the incoming domain string before validation
(e.g., let trimmed = domain.trim() or assign back to domain) and then throw the
Error if the trimmed value is empty. Update the validation in
proxy-dns-resolver.ts (the domain parameter check) to use the trimmed value so
inputs like " " are rejected before sending upstream.
- Around line 14-18: In queryDns (proxy-dns-resolver.ts) add a request timeout
and stricter domain validation: before building the URL, validate the domain by
trimming (e.g., if (!domain || domain.trim().length === 0) throw new Error(...))
so whitespace-only strings are rejected; when calling fetch(url) use an
AbortSignal with AbortSignal.timeout(TIMEOUT_MS) (Node 18+), pass the signal
option to fetch, and handle the abort/timeout by catching the thrown
DOMException/AbortError and rethrowing a clear error (or propagate) so a hung
proxy won't block the resolver chain; keep the timeout value as a configurable
constant near queryDns.
---
Nitpick comments:
In `@src/index.ts`:
- Around line 27-32: Add a focused contract test that asserts the exact order of
the exported defaultDnsResolvers array to prevent accidental reorderings: write
a unit test that imports defaultDnsResolvers and verifies its sequence equals
[googleDnsResolver, cloudflareDnsResolver, proxyDnsResolver, aliDnsResolver] (or
compares names/identifiers if direct object equality is brittle); name the test
to indicate it guards resolver fallback order and keep it small and isolated so
future refactors will fail if the order changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ea4ddf77-8d9f-409e-a414-0e029def52d3
📒 Files selected for processing (4)
src/index.tssrc/util/dns-resolvers/dns-resolvers.test.tssrc/util/dns-resolvers/index.tssrc/util/dns-resolvers/proxy-dns-resolver.ts
|
🎉 This PR is included in version 2.21.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary by CodeRabbit
New Features
Tests