File tree 3 files changed +50
-3
lines changed
3 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -726,7 +726,15 @@ class Server {
726
726
}
727
727
728
728
listen ( port , hostname , fn ) {
729
- this . hostname = hostname ;
729
+ if ( hostname === 'local-ip' ) {
730
+ this . hostname = internalIp . v4 . sync ( ) || internalIp . v6 . sync ( ) ;
731
+ } else if ( hostname === 'local-ipv4' ) {
732
+ this . hostname = internalIp . v4 . sync ( ) ;
733
+ } else if ( hostname === 'local-ipv6' ) {
734
+ this . hostname = internalIp . v6 . sync ( ) ;
735
+ } else {
736
+ this . hostname = hostname ;
737
+ }
730
738
731
739
if ( typeof port !== 'undefined' && port !== this . options . port ) {
732
740
this . logger . warn (
@@ -739,8 +747,7 @@ class Server {
739
747
// eslint-disable-next-line no-shadow
740
748
. then ( ( port ) => {
741
749
this . port = port ;
742
-
743
- return this . server . listen ( port , hostname , ( err ) => {
750
+ return this . server . listen ( port , this . hostname , ( err ) => {
744
751
if ( this . options . hot || this . options . liveReload ) {
745
752
this . createSocketServer ( ) ;
746
753
}
Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ exports[`CLI --host <IPv4>: stderr 1`] = `
17
17
<i > [webpack-dev-server] Content not from webpack is served from '<cwd >/public' directory"
18
18
`;
19
19
20
+ exports[`CLI --host <local-ip >: stderr 1`] = `
21
+ "<i > [webpack-dev-server] Project is running at http://<network-ip-v4 >:<port >/ (IPv4)
22
+ <i > [webpack-dev-server] Content not from webpack is served from '<cwd >/public' directory"
23
+ `;
24
+
25
+ exports[`CLI --host <local-ipv4 >: stderr 1`] = `
26
+ "<i > [webpack-dev-server] Project is running at http://<network-ip-v4 >:<port >/ (IPv4)
27
+ <i > [webpack-dev-server] Content not from webpack is served from '<cwd >/public' directory"
28
+ `;
29
+
20
30
exports[`CLI --host 0.0.0.0 (IPv4): stderr 1`] = `
21
31
"<i > [webpack-dev-server] Project is running at:
22
32
<i > [webpack-dev-server] Local: http://localhost:<port >/
Original file line number Diff line number Diff line change @@ -188,6 +188,36 @@ describe('CLI', () => {
188
188
. catch ( done ) ;
189
189
} ) ;
190
190
191
+ it ( '--host <local-ip>' , ( done ) => {
192
+ testBin ( '--host local-ip' )
193
+ . then ( ( output ) => {
194
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
195
+
196
+ done ( ) ;
197
+ } )
198
+ . catch ( done ) ;
199
+ } ) ;
200
+
201
+ it ( '--host <local-ipv4>' , ( done ) => {
202
+ testBin ( '--host local-ipv4' )
203
+ . then ( ( output ) => {
204
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
205
+
206
+ done ( ) ;
207
+ } )
208
+ . catch ( done ) ;
209
+ } ) ;
210
+
211
+ it . skip ( '--host <local-ipv6>' , ( done ) => {
212
+ testBin ( '--host local-ipv6' )
213
+ . then ( ( output ) => {
214
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
215
+
216
+ done ( ) ;
217
+ } )
218
+ . catch ( done ) ;
219
+ } ) ;
220
+
191
221
it ( '--host localhost --port 9999' , ( done ) => {
192
222
testBin ( '--host localhost --port 9999' )
193
223
. then ( ( output ) => {
You can’t perform that action at this time.
0 commit comments