axios-cached-dns-resolve
Advanced tools
Comparing version
@@ -11,2 +11,3 @@ /* eslint-disable no-plusplus */ | ||
const dnsResolve = util.promisify(dns.resolve) | ||
const dnsLookup = util.promisify(dns.lookup) | ||
@@ -145,3 +146,3 @@ export const config = { | ||
const ips = await dnsResolve(host) | ||
const ips = await resolve(host) | ||
dnsEntry = { | ||
@@ -176,3 +177,3 @@ host, | ||
const ips = await dnsResolve(value.host) | ||
const ips = await resolve(value.host) | ||
value.ips = ips | ||
@@ -195,2 +196,20 @@ value.updatedTs = Date.now() | ||
/** | ||
* | ||
* @param host | ||
* @returns {*[]} | ||
*/ | ||
async function resolve(host) { | ||
let ips | ||
try { | ||
ips = await dnsResolve(host) | ||
} catch (e) { | ||
const lookupResp = await dnsLookup(host) | ||
if (lookupResp.address == null) throw new Error(`fallback to dnsLookup returned no address ${host}`) | ||
// lookup only returns 1 host, resolve returns multiple for round-robin | ||
ips = [lookupResp.address] | ||
} | ||
return ips | ||
} | ||
function recordError(err, errMesg) { | ||
@@ -197,0 +216,0 @@ ++stats.errors |
{ | ||
"name": "axios-cached-dns-resolve", | ||
"version": "3.0.6", | ||
"version": "3.1.0", | ||
"main": "index", | ||
@@ -35,11 +35,11 @@ "description": "Caches dns resolutions made with async dns.resolve instead of default sync dns.lookup, refreshes in background", | ||
"ava": "^3.15.0", | ||
"axios": "^0.26.1", | ||
"body-parser": "^1.19.2", | ||
"axios": "^0.27.2", | ||
"body-parser": "^1.20.0", | ||
"delay": "^5.0.0", | ||
"eslint": "^8.12.0", | ||
"eslint": "^8.15.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-watch": "^8.0.0", | ||
"esm": "^3.2.25", | ||
"express": "^4.17.3", | ||
"express": "^4.18.1", | ||
"ignore-styles": "^5.0.1" | ||
@@ -49,6 +49,6 @@ }, | ||
"json-stringify-safe": "^5.0.1", | ||
"lru-cache": "^7.7.1", | ||
"pino": "^7.9.2", | ||
"pino-pretty": "^7.6.0" | ||
"lru-cache": "^7.10.0", | ||
"pino": "^7.11.0", | ||
"pino-pretty": "^7.6.1" | ||
} | ||
} |
12611
3.79%211
9.33%Updated
Updated
Updated