-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: initial implementation #1
Merged
Merged
Changes from 2 commits
Commits
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 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 |
---|---|---|
|
@@ -102,3 +102,4 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
package-lock.json |
This file contains 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,40 @@ | ||
language: node_js | ||
cache: npm | ||
stages: | ||
- check | ||
- test | ||
- cov | ||
|
||
node_js: | ||
- 'lts/*' | ||
- 'stable' | ||
|
||
os: | ||
- linux | ||
- osx | ||
|
||
script: npx nyc -s npm run test:node -- --bail | ||
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov | ||
|
||
jobs: | ||
include: | ||
- stage: check | ||
script: | ||
- npm run lint | ||
|
||
- stage: test | ||
name: chrome | ||
addons: | ||
chrome: stable | ||
script: | ||
- npx aegir test -t browser | ||
|
||
- stage: test | ||
name: firefox | ||
addons: | ||
firefox: latest | ||
script: | ||
- npx aegir test -t browser -- --browsers FirefoxHeadless | ||
|
||
notifications: | ||
email: false |
This file contains 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 |
---|---|---|
@@ -1,2 +1,189 @@ | ||
# dns-over-http-client | ||
DNS over HTTP client | ||
# dns-over-http-resolver | ||
|
||
[![Build Status](https://travis-ci.org/vasco-santos/dns-over-http-resolver.svg?branch=master)](https://travis-ci.org/vasco-santos/dns-over-http-resolver) | ||
[![dependencies Status](https://david-dm.org/vasco-santos/dns-over-http-resolver/status.svg)](https://david-dm.org/vasco-santos/dns-over-http-resolver) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
|
||
> DNS over HTTP resolver | ||
|
||
Isomorphic DNS over HTTP resolver using fetch. | ||
|
||
API based on [Node.js' dns promises API](https://nodejs.org/dist/latest-v14.x/docs/api/dns.html#dns_dns_promises_api), allowing the native `dns` module to be used if available when relying on this API. | ||
|
||
## Install | ||
|
||
```sh | ||
npm i dns-over-http-resolver | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
const DnsOverHttpResolver = require('dns-over-http-resolver') | ||
``` | ||
|
||
Use Node.js' dns promises API if available. | ||
```js | ||
const { Resolver } = require('dns').promises || require('dns-over-http-resolver') | ||
``` | ||
|
||
[Cloudflare](https://cloudflare-dns.com/dns-query) and [Google](https://dns.google/resolve) DNS servers are used by default. They can be replaced via the API. | ||
|
||
## API | ||
|
||
### resolve(hostname, rrType) | ||
|
||
Uses the DNS protocol to resolve the given host name into a DNS record. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| hostname | `string` | host name to resolve | | ||
| [rrType] | `string` | resource record type (default: 'A') | | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `Promise<Array<string>>` | returns a Promise resolving a DNS record according to its type | | ||
|
||
#### Example | ||
|
||
```js | ||
const DnsOverHttpResolver = require('dns-over-http-resolver') | ||
const resolver = new DnsOverHttpResolver() | ||
|
||
const hostname = 'google.com' | ||
const recordType = 'TXT' | ||
|
||
const dnsRecord = await resolver.resolve(hostname, recordType) | ||
``` | ||
|
||
### resolve4(hostname) | ||
|
||
Uses the DNS protocol to resolve the given host name into IPv4 addresses. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| hostname | `string` | host name to resolve | | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `Promise<Array<string>>` | returns a Promise resolving IPv4 addresses | | ||
|
||
#### Example | ||
|
||
```js | ||
const DnsOverHttpResolver = require('dns-over-http-resolver') | ||
const resolver = new DnsOverHttpResolver() | ||
|
||
const hostname = 'google.com' | ||
|
||
const address = await resolver.resolve4(hostname) // ['216.58.212.142'] | ||
``` | ||
|
||
### resolve6(hostname) | ||
|
||
Uses the DNS protocol to resolve the given host name into IPv6 addresses. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| hostname | `string` | host name to resolve | | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `Promise<Array<string>>` | returns a Promise resolving IPv6 addresses | | ||
|
||
#### Example | ||
|
||
```js | ||
const DnsOverHttpResolver = require('dns-over-http-resolver') | ||
const resolver = new DnsOverHttpResolver() | ||
|
||
const hostname = 'google.com' | ||
|
||
const address = await resolver.resolve6(hostname) // ['2a00:1450:4001:801::200e'] | ||
``` | ||
|
||
### resolveTxt(hostname) | ||
|
||
Uses the DNS protocol to resolve the given host name into a Text Record. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| hostname | `string` | host name to resolve | | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `Promise<Array<Array<string>>>` | returns a Promise resolving a Text Record | | ||
|
||
#### Example | ||
|
||
```js | ||
const DnsOverHttpResolver = require('dns-over-http-resolver') | ||
const resolver = new DnsOverHttpResolver() | ||
|
||
const hostname = 'google.com' | ||
|
||
const address = await resolver.resolveTxt(hostname) // [['v=spf1 -all']] | ||
``` | ||
|
||
### getServers() | ||
|
||
Get an array of the IP addresses currently configured for DNS resolution. | ||
These addresses are formatted according to RFC 5952. It can include a custom port. | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `Array<string>` | returns array of DNS servers used | | ||
|
||
#### Example | ||
|
||
```js | ||
const DnsOverHttpResolver = require('dns-over-http-resolver') | ||
|
||
const resolver = new DnsOverHttpResolver() | ||
const servers = resolver.getServers() | ||
``` | ||
|
||
### setServers(servers) | ||
|
||
Sets the IP address and port of servers to be used when performing DNS resolution. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| servers | `Array<string>` | Array of RFC 5952 formatted addresses. | | ||
|
||
#### Example | ||
|
||
```js | ||
const DnsOverHttpResolver = require('dns-over-http-resolver') | ||
|
||
const resolver = new DnsOverHttpResolver() | ||
resolver.setServers(['https://cloudflare-dns.com/dns-query']) | ||
``` | ||
|
||
## Contribute | ||
|
||
Feel free to dive in! [Open an issue](https://github.com/vasco-santos/dns-over-http-resolver/issues/new) or submit PRs. | ||
|
||
## License | ||
|
||
[MIT](LICENSE) © Vasco Santos |
This file contains 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,44 @@ | ||
{ | ||
"name": "dns-over-http-resolver", | ||
"version": "0.0.0", | ||
"description": "DNS over HTTP resolver", | ||
"main": "src/index.js", | ||
"author": "Vasco Santos", | ||
"scripts": { | ||
"test": "aegir test -t node -t browser", | ||
"test:browser": "aegir test -t browser", | ||
"test:node": "aegir test -t node", | ||
"lint": "aegir lint", | ||
"release": "aegir release --docs", | ||
"release-minor": "aegir release --type minor --docs", | ||
"release-major": "aegir release -t node -t browser --type major --docs", | ||
"build": "aegir build" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"devDependencies": { | ||
"aegir": "^27.0.0", | ||
"ipfs-utils": "^4.0.0", | ||
"sinon": "^9.2.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vasco-santos/dns-over-http-resolver.git" | ||
}, | ||
"keywords": [ | ||
"doh", | ||
"dns", | ||
"http" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/vasco-santos/dns-over-http-resolver/issues" | ||
}, | ||
"homepage": "https://github.com/vasco-santos/dns-over-http-resolver#readme", | ||
"dependencies": { | ||
"debug": "^4.2.0", | ||
"native-fetch": "^2.0.1" | ||
} | ||
} |
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.
This example isn't going to work. I'd just specify that users can use
require('dns').promises
in Node.js in lieu of this module.