Comparing version
@@ -1,8 +0,14 @@ | ||
const Pkg = require('./../package.json'); | ||
require('es6-promise').polyfill(); | ||
require('isomorphic-fetch'); | ||
const IsIP = require('is-ip'); | ||
const Url = require ('url'); | ||
const Dohdec = require('dohdec'); | ||
const Fetch = require('node-fetch'); | ||
const Pkg = require('./../package.json'); | ||
const IsIP = require('is-ip'); | ||
const Url = require ('url'); | ||
const Qs = require('querystring'); | ||
const Fetch = fetch; | ||
const CT_TYPE = 'application/dns-json'; | ||
const USER_AGENT = `${Pkg.name} v${Pkg.version}`; | ||
const TYPES = { | ||
@@ -14,3 +20,4 @@ DNS_PROVIDERS: { | ||
DNS_OVER_HTTPS: { | ||
GOOGLE: 'https://dns.google.com/resolve' | ||
GOOGLE: 'https://dns.google.com/resolve', | ||
CLOUDFLARE: 'https://cloudflare-dns.com/dns-query' | ||
} | ||
@@ -28,2 +35,23 @@ }; | ||
getDns () { | ||
return async (name, opts) => { | ||
opts = Object.assign({}, { | ||
rrtype: 'A', | ||
url: TYPES.DNS_OVER_HTTPS.CLOUDFLARE, | ||
name: Qs.escape(name) | ||
}, opts); | ||
opts.rrtype = opts.rrtype.toUpperCase(); | ||
const lookup = await fetch( | ||
`${opts.url}?ct=${CT_TYPE}&name=${opts.name}&type=${opts.rrtype}`, { | ||
headers: { | ||
'User-Agent': USER_AGENT | ||
} | ||
}); | ||
return lookup.json(); | ||
}; | ||
} | ||
set () { | ||
@@ -44,5 +72,6 @@ let ctx = this; | ||
const getDns = ctx.getDns(); | ||
const _dnsRequest = (provider === TYPES.DNS_PROVIDERS.CLOUDFLARE) ? | ||
await Dohdec(_url.hostname) : | ||
await Dohdec(_url.hostname, { | ||
await getDns(_url.hostname) : | ||
await getDns(_url.hostname, { | ||
url: TYPES.DNS_OVER_HTTPS[TYPES.DNS_PROVIDERS.GOOGLE] | ||
@@ -49,0 +78,0 @@ }); |
{ | ||
"name": "fdoh", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Fetch DNS over HTTPS", | ||
@@ -33,4 +33,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"dohdec": "^1.0.0", | ||
"is-ip": "^2.0.0" | ||
"es6-promise": "^4.2.4", | ||
"is-ip": "^2.0.0", | ||
"isomorphic-fetch": "^2.2.1", | ||
"querystring": "^0.2.0", | ||
"url": "^0.11.0" | ||
}, | ||
@@ -37,0 +40,0 @@ "devDependencies": { |
@@ -9,3 +9,3 @@ # FDOH | ||
The point of this utility is to be able to utilize node-fetch with your DNS queries running over HTTPS from Cloudflare [1.1.1.1](https://1.1.1.1) or Google DNS over HTTPS. | ||
The point of this utility is to be able to utilize fetch with your DNS queries running over HTTPS from Cloudflare [1.1.1.1](https://1.1.1.1) or Google DNS over HTTPS. | ||
@@ -39,6 +39,1 @@ ### Fetch Example | ||
### Dependencies | ||
- [dohdec](https://github.com/hildjj/dohdec) | ||
- [is-ip](https://github.com/sindresorhus/is-ip) |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
9205
22.75%10
11.11%121
23.47%5
150%38
-11.63%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed