fix: display correct address when multiple network adapters present (#4083)

fixes #3266

see https://github.com/vuejs/vue-cli/issues/3266#issuecomment-493487325

Thanks to @shenliangv
This commit is contained in:
Haoqun Jiang
2019-06-04 23:57:31 +08:00
committed by GitHub
parent 78e1c4cf63
commit f3d2c1c133
2 changed files with 4 additions and 1 deletions
@@ -9,6 +9,7 @@
const url = require('url')
const chalk = require('chalk')
const address = require('address')
const defaultGateway = require('default-gateway')
module.exports = function prepareUrls (protocol, host, port, pathname = '/') {
const formatUrl = hostname =>
@@ -33,7 +34,8 @@ module.exports = function prepareUrls (protocol, host, port, pathname = '/') {
prettyHost = 'localhost'
try {
// This can only return an IPv4 address
lanUrlForConfig = address.ip()
const result = defaultGateway.v4.sync()
lanUrlForConfig = address.ip(result && result.interface)
if (lanUrlForConfig) {
// Check if the address is a private ip
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
+1
View File
@@ -46,6 +46,7 @@
"cssnano": "^4.1.10",
"current-script-polyfill": "^1.0.0",
"debug": "^4.1.1",
"default-gateway": "^4.2.0",
"dotenv": "^8.0.0",
"dotenv-expand": "^5.1.0",
"file-loader": "^3.0.1",