Release 4.8.1

This commit is contained in:
tsightler
2021-09-08 22:18:39 -04:00
parent b0670ba665
commit 2b0d43f66c
5 changed files with 49 additions and 19 deletions

View File

@@ -1,4 +1,7 @@
const fs = require('fs')
const dns = require('dns')
const os = require('os')
const { promisify } = require('util')
class Utils
{
@@ -30,19 +33,24 @@ class Utils
}
async getHostFqdn() {
const dns = require('dns')
const os = require('os')
const { promisify } = require('util')
const pLookup = promisify(dns.lookup)
const pLookupService = promisify(dns.lookupService)
try {
return (await pLookupService((await pLookup(os.hostname())).address, 0)).hostname
return await pLookupService(await this.getHostIp(), 0).hostname
} catch {
console.log('Failed to resolve FQDN, using os.hostname() instead')
return os.hostname()
}
}
async getHostIp() {
const pLookup = promisify(dns.lookup)
try {
return await pLookup(os.hostname()).address
} catch {
console.log('Failed to resolve hostname IP address, returning localhost instead')
return 'localhost'
}
}
}
module.exports = new Utils()