diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index eeaff0ef8f..e249dcb6d2 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -7,6 +7,7 @@ import fs from 'fs-extra' import consola from 'consola' import chalk from 'chalk' import esm from 'esm' +import ip from 'ip' import Options from '../common/options' import { sequence } from '../common/utils' @@ -126,8 +127,10 @@ export default class Nuxt { } ({ address: host, port } = server.address()) - if (['127.0.0.1', '0.0.0.0'].includes(host)) { + if (host === '127.0.0.1') { host = 'localhost' + } else if (host === '0.0.0.0') { + host = ip.address() } const listenURL = chalk.underline.blue(`http://${host}:${port}`) diff --git a/package.json b/package.json index 37cf1778bb..70f30b4ef3 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "hash-sum": "^1.0.2", "html-minifier": "^3.5.19", "html-webpack-plugin": "^3.2.0", + "ip": "^1.1.5", "launch-editor-middleware": "^2.2.1", "lodash": "^4.17.10", "lru-cache": "^4.1.3", diff --git a/yarn.lock b/yarn.lock index 096b69db70..ff2f718a91 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3702,6 +3702,10 @@ invert-kv@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" +ip@^1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a" + ipaddr.js@1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.6.0.tgz#e3fa357b773da619f26e95f049d055c72796f86b"