Skip to content

Commit 41b4d37

Browse files
committed
fix: display correct address when multiple network adapters present (#4083)
fixes #3266 see #3266 (comment) Thanks to @shenliangv (cherry picked from commit f3d2c1c)
1 parent bcc53db commit 41b4d37

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

packages/@vue/cli-service/lib/util/prepareURLs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
const url = require('url')
1010
const chalk = require('chalk')
1111
const address = require('address')
12+
const defaultGateway = require('default-gateway')
1213

1314
module.exports = function prepareUrls (protocol, host, port, pathname = '/') {
1415
const formatUrl = hostname =>
@@ -33,7 +34,8 @@ module.exports = function prepareUrls (protocol, host, port, pathname = '/') {
3334
prettyHost = 'localhost'
3435
try {
3536
// This can only return an IPv4 address
36-
lanUrlForConfig = address.ip()
37+
const result = defaultGateway.v4.sync()
38+
lanUrlForConfig = address.ip(result && result.interface)
3739
if (lanUrlForConfig) {
3840
// Check if the address is a private ip
3941
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces

packages/@vue/cli-service/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"cssnano": "^4.1.10",
4747
"current-script-polyfill": "^1.0.0",
4848
"debug": "^4.1.1",
49+
"default-gateway": "^4.2.0",
4950
"dotenv": "^7.0.0",
5051
"dotenv-expand": "^5.1.0",
5152
"escape-string-regexp": "^1.0.5",

0 commit comments

Comments
 (0)