@@ -12,7 +12,6 @@ const url = require('url');
1212const http = require ( 'http' ) ;
1313const https = require ( 'https' ) ;
1414const ip = require ( 'ip' ) ;
15- const sockjs = require ( 'sockjs' ) ;
1615const semver = require ( 'semver' ) ;
1716const killable = require ( 'killable' ) ;
1817const chokidar = require ( 'chokidar' ) ;
@@ -32,26 +31,7 @@ const createDomain = require('./utils/createDomain');
3231const runBonjour = require ( './utils/runBonjour' ) ;
3332const routes = require ( './utils/routes' ) ;
3433const 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' ) ;
5535
5636// Workaround for node ^8.6.0, ^9.0.0
5737// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
@@ -671,20 +651,9 @@ class Server {
671651 }
672652
673653 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 ) ;
686655
687- socket . on ( 'connection' , ( connection ) => {
656+ this . socketServer . onConnection ( ( connection ) => {
688657 if ( ! connection ) {
689658 return ;
690659 }
@@ -736,10 +705,6 @@ class Server {
736705
737706 this . _sendStats ( [ connection ] , this . getStats ( this . _stats ) , true ) ;
738707 } ) ;
739-
740- socket . installHandlers ( this . listeningApp , {
741- prefix : this . sockPath ,
742- } ) ;
743708 }
744709
745710 listen ( port , hostname , fn ) {
@@ -762,7 +727,7 @@ class Server {
762727
763728 close ( cb ) {
764729 this . sockets . forEach ( ( socket ) => {
765- socket . close ( ) ;
730+ this . socketServer . close ( socket ) ;
766731 } ) ;
767732
768733 this . sockets = [ ] ;
@@ -923,7 +888,7 @@ class Server {
923888 // eslint-disable-next-line
924889 sockWrite ( sockets , type , data ) {
925890 sockets . forEach ( ( socket ) => {
926- socket . write ( JSON . stringify ( { type, data } ) ) ;
891+ this . socketServer . send ( socket , JSON . stringify ( { type, data } ) ) ;
927892 } ) ;
928893 }
929894
0 commit comments