From dd3704f8a7e39b019085ac9e57db398dccf876bd Mon Sep 17 00:00:00 2001 From: Boris Serdiuk Date: Mon, 2 Jul 2018 21:29:20 +0200 Subject: [PATCH] Handle DNS lookup failures (#439) When lookup fails, it throws an exception, that prevent other code from being executed fixes #437 --- bin/serve.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/serve.js b/bin/serve.js index 08557add..e274a9c1 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -173,10 +173,14 @@ const startEndpoint = (endpoint, config, args) => { localAddress = details; } else if (typeof details === 'object' && details.port) { const address = details.address === '::' ? 'localhost' : details.address; - const {address: ip} = await lookup(os.hostname()); localAddress = `http://${address}:${details.port}`; - networkAddress = `http://${ip}:${details.port}`; + try { + const {address: ip} = await lookup(os.hostname()); + networkAddress = `http://${ip}:${details.port}`; + } catch (err) { + console.error(error(`DNS lookup failed: ${err.message}`)); + } } if (isTTY && process.env.NODE_ENV !== 'production') {