Skip to content

Commit f3d2c1c

Browse files
authored
fix: display correct address when multiple network adapters present (#4083)
fixes #3266 see #3266 (comment) Thanks to @shenliangv
1 parent 78e1c4c commit f3d2c1c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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

+3-1
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

+1
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": "^8.0.0",
5051
"dotenv-expand": "^5.1.0",
5152
"file-loader": "^3.0.1",

0 commit comments

Comments
 (0)