@@ -6,6 +6,7 @@ const url = require('url');
6
6
const http = require ( 'http' ) ;
7
7
const https = require ( 'https' ) ;
8
8
const ip = require ( 'ip' ) ;
9
+ const internalIp = require ( 'internal-ip' ) ;
9
10
const killable = require ( 'killable' ) ;
10
11
const chokidar = require ( 'chokidar' ) ;
11
12
const express = require ( 'express' ) ;
@@ -21,8 +22,8 @@ const { validate } = require('schema-utils');
21
22
const normalizeOptions = require ( './utils/normalizeOptions' ) ;
22
23
const updateCompiler = require ( './utils/updateCompiler' ) ;
23
24
const getCertificate = require ( './utils/getCertificate' ) ;
24
- const status = require ( './utils/status ' ) ;
25
- const createDomain = require ( './utils/createDomain ' ) ;
25
+ const colors = require ( './utils/colors ' ) ;
26
+ const runOpen = require ( './utils/runOpen ' ) ;
26
27
const runBonjour = require ( './utils/runBonjour' ) ;
27
28
const routes = require ( './utils/routes' ) ;
28
29
const getSocketServerImplementation = require ( './utils/getSocketServerImplementation' ) ;
@@ -580,17 +581,91 @@ class Server {
580
581
}
581
582
582
583
showStatus ( ) {
583
- const suffix = '/' ;
584
- const uri = `${ createDomain ( this . options , this . server ) } ${ suffix } ` ;
584
+ const useColor = getColorsOption ( getCompilerConfigArray ( this . compiler ) ) ;
585
585
586
- const configArr = getCompilerConfigArray ( this . compiler ) ;
587
- const colors = getColorsOption ( configArr ) ;
586
+ const protocol = this . options . https ? 'https' : 'http' ;
587
+ const { hostname, port } = this ;
588
+ const prettyPrintUrl = ( newHostname ) =>
589
+ url . format ( { protocol, hostname : newHostname , port, pathname : '/' } ) ;
590
+
591
+ let prettyHostname ;
592
+ let lanUrlForTerminal ;
593
+
594
+ if ( hostname === '0.0.0.0' || hostname === '::' ) {
595
+ prettyHostname = 'localhost' ;
596
+
597
+ const localIP =
598
+ hostname === '::' ? internalIp . v6 . sync ( ) : internalIp . v4 . sync ( ) ;
599
+
600
+ if ( localIP ) {
601
+ lanUrlForTerminal = prettyPrintUrl ( localIP ) ;
602
+ }
603
+ } else {
604
+ prettyHostname = hostname ;
605
+ }
588
606
589
- status ( uri , this . options , this . logger , colors ) ;
607
+ const localUrlForTerminal = prettyPrintUrl ( prettyHostname ) ;
608
+
609
+ if ( lanUrlForTerminal ) {
610
+ this . logger . info ( 'Project is running at:' ) ;
611
+ this . logger . info ( `Local: ${ colors . info ( useColor , localUrlForTerminal ) } ` ) ;
612
+ this . logger . info (
613
+ `On Your Network: ${ colors . info ( useColor , lanUrlForTerminal ) } `
614
+ ) ;
615
+ } else {
616
+ this . logger . info (
617
+ `Project is running at ${ colors . info ( useColor , localUrlForTerminal ) } `
618
+ ) ;
619
+ }
620
+
621
+ if (
622
+ this . options . dev &&
623
+ typeof this . options . dev . publicPath !== 'undefined'
624
+ ) {
625
+ this . options . info (
626
+ `webpack output is served from '${ colors . info (
627
+ useColor ,
628
+ this . options . dev . publicPath === 'auto'
629
+ ? '/'
630
+ : this . options . dev . publicPath
631
+ ) } ' URL`
632
+ ) ;
633
+ }
634
+
635
+ if ( this . options . static && this . options . static . length > 0 ) {
636
+ this . logger . info (
637
+ `Content not from webpack is served from '${ colors . info (
638
+ useColor ,
639
+ this . options . static
640
+ . map ( ( staticOption ) => staticOption . directory )
641
+ . join ( ', ' )
642
+ ) } ' directory`
643
+ ) ;
644
+ }
645
+
646
+ if ( this . options . historyApiFallback ) {
647
+ this . logger . info (
648
+ `404s will fallback to '${ colors . info (
649
+ useColor ,
650
+ this . options . historyApiFallback . index || '/index.html'
651
+ ) } '`
652
+ ) ;
653
+ }
654
+
655
+ if ( this . options . bonjour ) {
656
+ this . logger . info (
657
+ 'Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'
658
+ ) ;
659
+ }
660
+
661
+ if ( this . options . open ) {
662
+ runOpen ( localUrlForTerminal , this . options , this . logger ) ;
663
+ }
590
664
}
591
665
592
666
listen ( port , hostname , fn ) {
593
667
this . hostname = hostname ;
668
+
594
669
if ( typeof port !== 'undefined' && port !== this . options . port ) {
595
670
this . logger . warn (
596
671
'The port specified in options and the port passed as an argument is different.'
0 commit comments