1.2.12 • Published 1 year ago

doh-resolver v1.2.12

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

doh-resolver

A DNS-over-HTTPS resolver for Node.js.

Last version Coverage Status NPM Status

Install

$ npm install doh-resolver --save

Usage

It can be used as dns.resolve4 and/or dns.resolve6 drop-in replacement:

const DoHResolver = require('doh-resolver')
const resolver = new DoHResolver({ servers: ['1.1.1.1', '8.8.8.8'] })

resolver.resolve4('example.com', (error, addresses) => {
  if (error) throw error
  // Handle the result
})

When you specify more than one server, the result will be the fastest HTTP request into resolve.

Customize the request using your favorite HTTP client:

const DoHResolver = require('doh-resolver')
const { promisify } = require('util')

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  get: promisify(require('simple-get'))
})

Combine it with cacheable-lookup for caching lookups respecting TTL:

const CacheableLookup = require('cacheable-lookup')
const DoHResolver = require('doh-resolver')
const https = require('https')

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  onError: cb => cb(null, [])
})

const cacheable = new CacheableLookup({ resolver })

https.get('https://example.com', { lookup: cacheable.lookup }, response => {
  // Handle the response here
})

You can store the result via keyv to maximize cache HIT:

const CacheableLookup = require('cacheable-lookup')
const DoHResolver = require('doh-resolver')
const KeyvMulti = require('@keyvhq/multi')
const KeyvRedis = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')
const https = require('https')

const cache = new Keyv({
  store: new KeyvMulti({
    local: new Map(),
    remote: new KeyvRedis()
  })
})

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  onError: cb => cb(null, [])
})

const cacheable = new CacheableLookup({ resolver, cache })

https.get('https://example.com', { lookup: cacheable.lookup }, response => {
  // Handle the response here
})

If you want to debug timings, you can pass your own logger:

const DoHResolver = require('doh-resolver')

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  logger: require('debug-logfmt')('doh-resolver')
})

License

doh-resolver © Kiko Beats, released under the MIT License. Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats

1.2.12

1 year ago

1.2.11

1 year ago

1.2.10

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago