Skip to content

Commit

Permalink
fix: display correct address when multiple network adapters present (#…
Browse files Browse the repository at this point in the history
…4083)

fixes #3266

see #3266 (comment)

Thanks to @shenliangv

(cherry picked from commit f3d2c1c)
  • Loading branch information
haoqunjiang committed Jun 13, 2019
1 parent bcc53db commit 41b4d37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@vue/cli-service/lib/util/prepareURLs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"cssnano": "^4.1.10",
"current-script-polyfill": "^1.0.0",
"debug": "^4.1.1",
"default-gateway": "^4.2.0",
"dotenv": "^7.0.0",
"dotenv-expand": "^5.1.0",
"escape-string-regexp": "^1.0.5",
Expand Down

0 comments on commit 41b4d37

Please sign in to comment.