@@ -870,13 +870,18 @@ class Server {
870
870
// an IPv6-address in URLs,
871
871
// these are removed from the hostname in url.parse(),
872
872
// so we have the pure IPv6-address in hostname.
873
- if ( ip . isV4Format ( hostname ) || ip . isV6Format ( hostname ) ) {
873
+ // always allow localhost host, for convenience (hostname === 'localhost')
874
+ // allow hostname of listening address (hostname === this.hostname)
875
+ const isValidHostname =
876
+ ip . isV4Format ( hostname ) ||
877
+ ip . isV6Format ( hostname ) ||
878
+ hostname === 'localhost' ||
879
+ hostname === this . hostname ;
880
+
881
+ if ( isValidHostname ) {
874
882
return true ;
875
883
}
876
884
// always allow localhost host, for convenience
877
- if ( hostname === 'localhost' ) {
878
- return true ;
879
- }
880
885
// allow if hostname is in allowedHosts
881
886
if ( this . allowedHosts && this . allowedHosts . length ) {
882
887
for ( let hostIdx = 0 ; hostIdx < this . allowedHosts . length ; hostIdx ++ ) {
@@ -889,23 +894,18 @@ class Server {
889
894
// support "." as a subdomain wildcard
890
895
// e.g. ".example.com" will allow "example.com", "www.example.com", "subdomain.example.com", etc
891
896
if ( allowedHost [ 0 ] === '.' ) {
892
- // "example.com"
893
- if ( hostname === allowedHost . substring ( 1 ) ) {
894
- return true ;
895
- }
896
- // "*.example.com"
897
- if ( hostname . endsWith ( allowedHost ) ) {
897
+ // "example.com" (hostname === allowedHost.substring(1))
898
+ // "*.example.com" (hostname.endsWith(allowedHost))
899
+ if (
900
+ hostname === allowedHost . substring ( 1 ) ||
901
+ hostname . endsWith ( allowedHost )
902
+ ) {
898
903
return true ;
899
904
}
900
905
}
901
906
}
902
907
}
903
908
904
- // allow hostname of listening address
905
- if ( hostname === this . hostname ) {
906
- return true ;
907
- }
908
-
909
909
// also allow public hostname if provided
910
910
if ( typeof this . publicHost === 'string' ) {
911
911
const idxPublic = this . publicHost . indexOf ( ':' ) ;
@@ -955,13 +955,14 @@ class Server {
955
955
956
956
// send stats to a socket or multiple sockets
957
957
_sendStats ( sockets , stats , force ) {
958
- if (
958
+ const shouldEmit =
959
959
! force &&
960
960
stats &&
961
961
( ! stats . errors || stats . errors . length === 0 ) &&
962
962
stats . assets &&
963
- stats . assets . every ( ( asset ) => ! asset . emitted )
964
- ) {
963
+ stats . assets . every ( ( asset ) => ! asset . emitted ) ;
964
+
965
+ if ( shouldEmit ) {
965
966
return this . sockWrite ( sockets , 'still-ok' ) ;
966
967
}
967
968
0 commit comments