mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-11-02 12:54:04 +08:00
Release 4.8.0
This commit is contained in:
15
lib/utils.js
15
lib/utils.js
@@ -28,6 +28,21 @@ class Utils
|
||||
getISOTime(epoch) {
|
||||
return new Date(epoch).toISOString().slice(0,-5)+"Z"
|
||||
}
|
||||
|
||||
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
|
||||
} catch {
|
||||
console.log('Failed to resolve FQDN, using os.hostname() instead')
|
||||
return os.hostname()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Utils()
|
||||
|
||||
Reference in New Issue
Block a user