@@ -53,7 +53,7 @@ class Server {
53
53
54
54
this . setupHooks ( ) ;
55
55
this . setupApp ( ) ;
56
- this . setupCheckHostRoute ( ) ;
56
+ this . setupHostHeaderCheck ( ) ;
57
57
this . setupDevMiddleware ( ) ;
58
58
59
59
// Should be after `webpack-dev-middleware`, otherwise other middlewares might rewrite response
@@ -99,7 +99,7 @@ class Server {
99
99
msg = `${ msg } (${ addInfo } )` ;
100
100
}
101
101
102
- this . sockWrite ( this . sockets , 'progress-update' , {
102
+ this . sendMessage ( this . sockets , 'progress-update' , {
103
103
percent,
104
104
msg,
105
105
pluginName,
@@ -120,7 +120,7 @@ class Server {
120
120
setupHooks ( ) {
121
121
// Listening for events
122
122
const invalidPlugin = ( ) => {
123
- this . sockWrite ( this . sockets , 'invalid' ) ;
123
+ this . sendMessage ( this . sockets , 'invalid' ) ;
124
124
} ;
125
125
126
126
const addHooks = ( compiler ) => {
@@ -141,9 +141,9 @@ class Server {
141
141
}
142
142
}
143
143
144
- setupCheckHostRoute ( ) {
144
+ setupHostHeaderCheck ( ) {
145
145
this . app . all ( '*' , ( req , res , next ) => {
146
- if ( this . checkHost ( req . headers ) ) {
146
+ if ( this . checkHostHeader ( req . headers ) ) {
147
147
return next ( ) ;
148
148
}
149
149
@@ -464,7 +464,7 @@ class Server {
464
464
} ) ;
465
465
}
466
466
467
- createSocketServer ( ) {
467
+ createWebSocketServer ( ) {
468
468
this . socketServer = new this . SocketServerImplementation ( this ) ;
469
469
470
470
this . socketServer . onConnection ( ( connection , headers ) => {
@@ -479,8 +479,12 @@ class Server {
479
479
) ;
480
480
}
481
481
482
- if ( ! headers || ! this . checkHost ( headers ) || ! this . checkOrigin ( headers ) ) {
483
- this . sockWrite ( [ connection ] , 'error' , 'Invalid Host/Origin header' ) ;
482
+ if (
483
+ ! headers ||
484
+ ! this . checkHostHeader ( headers ) ||
485
+ ! this . checkOriginHeader ( headers )
486
+ ) {
487
+ this . sendMessage ( [ connection ] , 'error' , 'Invalid Host/Origin header' ) ;
484
488
485
489
this . socketServer . close ( connection ) ;
486
490
@@ -498,19 +502,23 @@ class Server {
498
502
} ) ;
499
503
500
504
if ( this . options . hot === true || this . options . hot === 'only' ) {
501
- this . sockWrite ( [ connection ] , 'hot' ) ;
505
+ this . sendMessage ( [ connection ] , 'hot' ) ;
502
506
}
503
507
504
508
if ( this . options . liveReload ) {
505
- this . sockWrite ( [ connection ] , 'liveReload' ) ;
509
+ this . sendMessage ( [ connection ] , 'liveReload' ) ;
506
510
}
507
511
508
512
if ( this . options . client . progress ) {
509
- this . sockWrite ( [ connection ] , 'progress' , this . options . client . progress ) ;
513
+ this . sendMessage (
514
+ [ connection ] ,
515
+ 'progress' ,
516
+ this . options . client . progress
517
+ ) ;
510
518
}
511
519
512
520
if ( this . options . client . overlay ) {
513
- this . sockWrite ( [ connection ] , 'overlay' , this . options . client . overlay ) ;
521
+ this . sendMessage ( [ connection ] , 'overlay' , this . options . client . overlay ) ;
514
522
}
515
523
516
524
if ( ! this . stats ) {
@@ -521,7 +529,7 @@ class Server {
521
529
} ) ;
522
530
}
523
531
524
- showStatus ( ) {
532
+ logStatus ( ) {
525
533
const useColor = getColorsOption ( getCompilerConfigArray ( this . compiler ) ) ;
526
534
const protocol = this . options . https ? 'https' : 'http' ;
527
535
const { address, port } = this . server . address ( ) ;
@@ -702,7 +710,7 @@ class Server {
702
710
this . options . host ,
703
711
( error ) => {
704
712
if ( this . options . hot || this . options . liveReload ) {
705
- this . createSocketServer ( ) ;
713
+ this . createWebSocketServer ( ) ;
706
714
}
707
715
708
716
if ( this . options . bonjour ) {
@@ -711,7 +719,7 @@ class Server {
711
719
runBonjour ( this . options ) ;
712
720
}
713
721
714
- this . showStatus ( ) ;
722
+ this . logStatus ( ) ;
715
723
716
724
if ( fn ) {
717
725
fn . call ( this . server , error ) ;
@@ -823,15 +831,15 @@ class Server {
823
831
next ( ) ;
824
832
}
825
833
826
- checkHost ( headers ) {
827
- return this . checkHeaders ( headers , 'host' ) ;
834
+ checkHostHeader ( headers ) {
835
+ return this . checkHeader ( headers , 'host' ) ;
828
836
}
829
837
830
- checkOrigin ( headers ) {
831
- return this . checkHeaders ( headers , 'origin' ) ;
838
+ checkOriginHeader ( headers ) {
839
+ return this . checkHeader ( headers , 'origin' ) ;
832
840
}
833
841
834
- checkHeaders ( headers , headerToCheck ) {
842
+ checkHeader ( headers , headerToCheck ) {
835
843
// allow user to opt out of this security check, at their own risk
836
844
// by explicitly enabling allowedHosts
837
845
if ( this . options . allowedHosts === 'all' ) {
@@ -912,7 +920,7 @@ class Server {
912
920
return false ;
913
921
}
914
922
915
- sockWrite ( sockets , type , data ) {
923
+ sendMessage ( sockets , type , data ) {
916
924
sockets . forEach ( ( socket ) => {
917
925
this . socketServer . send ( socket , JSON . stringify ( { type, data } ) ) ;
918
926
} ) ;
@@ -952,19 +960,19 @@ class Server {
952
960
stats . assets . every ( ( asset ) => ! asset . emitted ) ;
953
961
954
962
if ( shouldEmit ) {
955
- this . sockWrite ( sockets , 'still-ok' ) ;
963
+ this . sendMessage ( sockets , 'still-ok' ) ;
956
964
957
965
return ;
958
966
}
959
967
960
- this . sockWrite ( sockets , 'hash' , stats . hash ) ;
968
+ this . sendMessage ( sockets , 'hash' , stats . hash ) ;
961
969
962
970
if ( stats . errors . length > 0 ) {
963
- this . sockWrite ( sockets , 'errors' , stats . errors ) ;
971
+ this . sendMessage ( sockets , 'errors' , stats . errors ) ;
964
972
} else if ( stats . warnings . length > 0 ) {
965
- this . sockWrite ( sockets , 'warnings' , stats . warnings ) ;
973
+ this . sendMessage ( sockets , 'warnings' , stats . warnings ) ;
966
974
} else {
967
- this . sockWrite ( sockets , 'ok' ) ;
975
+ this . sendMessage ( sockets , 'ok' ) ;
968
976
}
969
977
}
970
978
@@ -1005,7 +1013,7 @@ class Server {
1005
1013
// disabling refreshing on changing the content
1006
1014
if ( this . options . liveReload ) {
1007
1015
watcher . on ( 'change' , ( ) => {
1008
- this . sockWrite ( this . sockets , 'static-changed' , watchPath ) ;
1016
+ this . sendMessage ( this . sockets , 'static-changed' , watchPath ) ;
1009
1017
} ) ;
1010
1018
}
1011
1019
0 commit comments