@@ -6,7 +6,6 @@ const path = require('path');
6
6
const fs = require ( 'fs' ) ;
7
7
const { promisify} = require ( 'util' ) ;
8
8
const { parse} = require ( 'url' ) ;
9
- const dns = require ( 'dns' ) ;
10
9
const os = require ( 'os' ) ;
11
10
12
11
// Packages
@@ -24,9 +23,10 @@ const compression = require('compression');
24
23
const pkg = require ( '../package' ) ;
25
24
26
25
const readFile = promisify ( fs . readFile ) ;
27
- const lookup = promisify ( dns . lookup ) ;
28
26
const compressionHandler = promisify ( compression ( ) ) ;
29
27
28
+ const interfaces = os . networkInterfaces ( ) ;
29
+
30
30
const warning = ( message ) => chalk `{yellow WARNING:} ${ message } ` ;
31
31
const info = ( message ) => chalk `{magenta INFO:} ${ message } ` ;
32
32
const error = ( message ) => chalk `{red ERROR:} ${ message } ` ;
@@ -154,6 +154,17 @@ const registerShutdown = (fn) => {
154
154
process . on ( 'exit' , wrapper ) ;
155
155
} ;
156
156
157
+ const getNetworkAddress = ( ) => {
158
+ for ( const name of Object . keys ( interfaces ) ) {
159
+ for ( const interface of interfaces [ name ] ) {
160
+ const { address, family, internal} = interface ;
161
+ if ( family === 'IPv4' && ! internal ) {
162
+ return address ;
163
+ }
164
+ }
165
+ }
166
+ } ;
167
+
157
168
const startEndpoint = ( endpoint , config , args , previous ) => {
158
169
const { isTTY} = process . stdout ;
159
170
const clipboard = args [ '--no-clipboard' ] !== true ;
@@ -188,14 +199,10 @@ const startEndpoint = (endpoint, config, args, previous) => {
188
199
localAddress = details ;
189
200
} else if ( typeof details === 'object' && details . port ) {
190
201
const address = details . address === '::' ? 'localhost' : details . address ;
202
+ const ip = getNetworkAddress ( ) ;
191
203
192
204
localAddress = `http://${ address } :${ details . port } ` ;
193
- try {
194
- const { address : ip } = await lookup ( os . hostname ( ) ) ;
195
- networkAddress = `http://${ ip } :${ details . port } ` ;
196
- } catch ( err ) {
197
- console . error ( error ( `DNS lookup failed: ${ err . message } ` ) ) ;
198
- }
205
+ networkAddress = `http://${ ip } :${ details . port } ` ;
199
206
}
200
207
201
208
if ( isTTY && process . env . NODE_ENV !== 'production' ) {
0 commit comments