@@ -12,7 +12,6 @@ const url = require('url');
12
12
const http = require ( 'http' ) ;
13
13
const https = require ( 'https' ) ;
14
14
const ip = require ( 'ip' ) ;
15
- const sockjs = require ( 'sockjs' ) ;
16
15
const semver = require ( 'semver' ) ;
17
16
const killable = require ( 'killable' ) ;
18
17
const chokidar = require ( 'chokidar' ) ;
@@ -32,26 +31,7 @@ const createDomain = require('./utils/createDomain');
32
31
const runBonjour = require ( './utils/runBonjour' ) ;
33
32
const routes = require ( './utils/routes' ) ;
34
33
const schema = require ( './options.json' ) ;
35
-
36
- // Workaround for sockjs@~0.3.19
37
- // sockjs will remove Origin header, however Origin header is required for checking host.
38
- // See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
39
- {
40
- // eslint-disable-next-line global-require
41
- const SockjsSession = require ( 'sockjs/lib/transport' ) . Session ;
42
- const decorateConnection = SockjsSession . prototype . decorateConnection ;
43
- SockjsSession . prototype . decorateConnection = function ( req ) {
44
- decorateConnection . call ( this , req ) ;
45
- const connection = this . connection ;
46
- if (
47
- connection . headers &&
48
- ! ( 'origin' in connection . headers ) &&
49
- 'origin' in req . headers
50
- ) {
51
- connection . headers . origin = req . headers . origin ;
52
- }
53
- } ;
54
- }
34
+ const SockJSServer = require ( './servers/SockJSServer' ) ;
55
35
56
36
// Workaround for node ^8.6.0, ^9.0.0
57
37
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
@@ -671,20 +651,9 @@ class Server {
671
651
}
672
652
673
653
createSocketServer ( ) {
674
- const socket = sockjs . createServer ( {
675
- // Use provided up-to-date sockjs-client
676
- sockjs_url : '/__webpack_dev_server__/sockjs.bundle.js' ,
677
- // Limit useless logs
678
- log : ( severity , line ) => {
679
- if ( severity === 'error' ) {
680
- this . log . error ( line ) ;
681
- } else {
682
- this . log . debug ( line ) ;
683
- }
684
- } ,
685
- } ) ;
654
+ this . socketServer = new SockJSServer ( this ) ;
686
655
687
- socket . on ( 'connection' , ( connection ) => {
656
+ this . socketServer . onConnection ( ( connection ) => {
688
657
if ( ! connection ) {
689
658
return ;
690
659
}
@@ -736,10 +705,6 @@ class Server {
736
705
737
706
this . _sendStats ( [ connection ] , this . getStats ( this . _stats ) , true ) ;
738
707
} ) ;
739
-
740
- socket . installHandlers ( this . listeningApp , {
741
- prefix : this . sockPath ,
742
- } ) ;
743
708
}
744
709
745
710
listen ( port , hostname , fn ) {
@@ -762,7 +727,7 @@ class Server {
762
727
763
728
close ( cb ) {
764
729
this . sockets . forEach ( ( socket ) => {
765
- socket . close ( ) ;
730
+ this . socketServer . close ( socket ) ;
766
731
} ) ;
767
732
768
733
this . sockets = [ ] ;
@@ -923,7 +888,7 @@ class Server {
923
888
// eslint-disable-next-line
924
889
sockWrite ( sockets , type , data ) {
925
890
sockets . forEach ( ( socket ) => {
926
- socket . write ( JSON . stringify ( { type, data } ) ) ;
891
+ this . socketServer . send ( socket , JSON . stringify ( { type, data } ) ) ;
927
892
} ) ;
928
893
}
929
894
0 commit comments