forked from TradeTrust/dnsprove
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
94ceabd
feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests
skydudie 02c4ae1
feat: enhance DNS resolvers with error handling and URL search parame…
skydudie 67ee6a6
feat: add domain validation to DNS resolvers
skydudie 8cba2d9
feat: use constant for TXT record type in AliDNS resolver
skydudie 0ab6226
feat: improve error handling for JSON parsing in DNS resolvers
skydudie ae5176e
feat: simplify fetch calls in DNS resolvers by removing redundant met…
skydudie 351544b
feat: update test cases to use trustvc.io domain and disable DNSSEC
skydudie 9885826
feat: add fallback mechanism to third DNS resolver when first two are…
skydudie d2eb43c
feat: streamline server setup in DNS resolver tests
skydudie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||
|
|
||
| /** Ali DNS JSON API uses numeric RRTYPE; 16 = TXT */ | ||
| const ALI_DNS_TXT_QUERY_TYPE = "16"; | ||
| export const aliDnsResolver: CustomDnsResolver = async (domain) => { | ||
| const url = new URL("https://dns.alidns.com/resolve"); | ||
|
|
||
| if (!domain) { | ||
| throw new Error("Domain is required"); | ||
| } | ||
|
|
||
| url.searchParams.set("name", domain); | ||
| url.searchParams.set("type", ALI_DNS_TXT_QUERY_TYPE); | ||
|
|
||
| const res = await fetch(url); | ||
|
|
||
| if (!res.ok) { | ||
| throw new Error(`Ali DNS request failed: HTTP ${res.status}`); | ||
| } | ||
|
|
||
| let data; | ||
| try { | ||
| data = await res.json(); | ||
| } catch { | ||
| throw new Error("Failed to parse DNS response JSON"); | ||
| } | ||
|
|
||
| return data as IDNSQueryResponse; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||
|
|
||
| export const cloudflareDnsResolver: CustomDnsResolver = async (domain) => { | ||
| const url = new URL("https://cloudflare-dns.com/dns-query"); | ||
|
|
||
| if (!domain) { | ||
| throw new Error("Domain is required"); | ||
| } | ||
|
|
||
| url.searchParams.set("name", domain); | ||
| url.searchParams.set("type", "TXT"); | ||
|
|
||
| const res = await fetch(url, { | ||
| headers: { Accept: "application/dns-json" }, | ||
| }); | ||
|
|
||
| if (!res.ok) { | ||
| throw new Error(`Cloudflare DNS request failed: HTTP ${res.status}`); | ||
| } | ||
|
|
||
| let data; | ||
| try { | ||
| data = await res.json(); | ||
| } catch { | ||
| throw new Error("Failed to parse DNS response JSON"); | ||
| } | ||
|
|
||
| return data as IDNSQueryResponse; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can prolly add in a check on Domain existence just in case anyone passes empty string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
67ee6a6