webpack-dev-server 4.3.1 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -33
- package/bin/cli-flags.js +507 -227
- package/bin/process-arguments.js +87 -7
- package/bin/webpack-dev-server.js +3 -0
- package/client/clients/SockJSClient.js +21 -2
- package/client/clients/WebSocketClient.js +16 -1
- package/client/index.js +39 -4
- package/client/modules/logger/index.js +46 -14
- package/client/modules/sockjs-client/index.js +20 -17
- package/client/socket.js +12 -9
- package/client/utils/log.js +6 -1
- package/client/utils/sendMessage.js +5 -0
- package/lib/Server.js +1935 -839
- package/lib/options.json +279 -21
- package/lib/servers/BaseServer.js +8 -0
- package/lib/servers/SockJSServer.js +42 -9
- package/lib/servers/WebsocketServer.js +66 -35
- package/package.json +28 -18
- package/types/bin/cli-flags.d.ts +934 -0
- package/types/bin/process-arguments.d.ts +50 -0
- package/types/bin/webpack-dev-server.d.ts +27 -0
- package/types/lib/Server.d.ts +3388 -0
- package/types/lib/servers/BaseServer.d.ts +15 -0
- package/types/lib/servers/SockJSServer.d.ts +12 -0
- package/types/lib/servers/WebsocketServer.d.ts +13 -0
package/lib/options.json
CHANGED
|
@@ -59,6 +59,9 @@
|
|
|
59
59
|
"progress": {
|
|
60
60
|
"$ref": "#/definitions/ClientProgress"
|
|
61
61
|
},
|
|
62
|
+
"reconnect": {
|
|
63
|
+
"$ref": "#/definitions/ClientReconnect"
|
|
64
|
+
},
|
|
62
65
|
"webSocketTransport": {
|
|
63
66
|
"$ref": "#/definitions/ClientWebSocketTransport"
|
|
64
67
|
},
|
|
@@ -71,7 +74,7 @@
|
|
|
71
74
|
},
|
|
72
75
|
"ClientLogging": {
|
|
73
76
|
"enum": ["none", "error", "warn", "info", "log", "verbose"],
|
|
74
|
-
"
|
|
77
|
+
"description": "Allows to set log level in the browser.",
|
|
75
78
|
"link": "https://webpack.js.org/configuration/dev-server/#logging"
|
|
76
79
|
},
|
|
77
80
|
"ClientOverlay": {
|
|
@@ -102,6 +105,19 @@
|
|
|
102
105
|
"link": "https://webpack.js.org/configuration/dev-server/#progress",
|
|
103
106
|
"type": "boolean"
|
|
104
107
|
},
|
|
108
|
+
"ClientReconnect": {
|
|
109
|
+
"description": "Tells dev-server the number of times it should try to reconnect the client.",
|
|
110
|
+
"link": "https://webpack.js.org/configuration/dev-server/#reconnect",
|
|
111
|
+
"anyOf": [
|
|
112
|
+
{
|
|
113
|
+
"type": "boolean"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"type": "number",
|
|
117
|
+
"minimum": 0
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
},
|
|
105
121
|
"ClientWebSocketTransport": {
|
|
106
122
|
"anyOf": [
|
|
107
123
|
{
|
|
@@ -191,7 +207,7 @@
|
|
|
191
207
|
},
|
|
192
208
|
"HTTP2": {
|
|
193
209
|
"type": "boolean",
|
|
194
|
-
"description": "Allows to serve over HTTP/2 using SPDY.",
|
|
210
|
+
"description": "Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option.",
|
|
195
211
|
"link": "https://webpack.js.org/configuration/dev-server/#devserverhttp2"
|
|
196
212
|
},
|
|
197
213
|
"HTTPS": {
|
|
@@ -205,11 +221,11 @@
|
|
|
205
221
|
"properties": {
|
|
206
222
|
"passphrase": {
|
|
207
223
|
"type": "string",
|
|
208
|
-
"description": "Passphrase for a pfx file."
|
|
224
|
+
"description": "Passphrase for a pfx file. Deprecated, use the `server.options.passphrase` option."
|
|
209
225
|
},
|
|
210
226
|
"requestCert": {
|
|
211
227
|
"type": "boolean",
|
|
212
|
-
"description": "Request for an SSL certificate."
|
|
228
|
+
"description": "Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option."
|
|
213
229
|
},
|
|
214
230
|
"ca": {
|
|
215
231
|
"anyOf": [
|
|
@@ -233,7 +249,7 @@
|
|
|
233
249
|
"instanceof": "Buffer"
|
|
234
250
|
}
|
|
235
251
|
],
|
|
236
|
-
"description": "Path to an SSL CA certificate or content of an SSL CA certificate."
|
|
252
|
+
"description": "Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option."
|
|
237
253
|
},
|
|
238
254
|
"cacert": {
|
|
239
255
|
"anyOf": [
|
|
@@ -257,7 +273,7 @@
|
|
|
257
273
|
"instanceof": "Buffer"
|
|
258
274
|
}
|
|
259
275
|
],
|
|
260
|
-
"description": "Path to an SSL CA certificate or content of an SSL CA certificate."
|
|
276
|
+
"description": "Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option."
|
|
261
277
|
},
|
|
262
278
|
"cert": {
|
|
263
279
|
"anyOf": [
|
|
@@ -281,7 +297,7 @@
|
|
|
281
297
|
"instanceof": "Buffer"
|
|
282
298
|
}
|
|
283
299
|
],
|
|
284
|
-
"description": "Path to an SSL certificate or content of an SSL certificate."
|
|
300
|
+
"description": "Path to an SSL certificate or content of an SSL certificate. Deprecated, use the `server.options.cert` option."
|
|
285
301
|
},
|
|
286
302
|
"crl": {
|
|
287
303
|
"anyOf": [
|
|
@@ -305,7 +321,7 @@
|
|
|
305
321
|
"instanceof": "Buffer"
|
|
306
322
|
}
|
|
307
323
|
],
|
|
308
|
-
"description": "Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists)."
|
|
324
|
+
"description": "Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the `server.options.crl` option."
|
|
309
325
|
},
|
|
310
326
|
"key": {
|
|
311
327
|
"anyOf": [
|
|
@@ -333,7 +349,7 @@
|
|
|
333
349
|
"instanceof": "Buffer"
|
|
334
350
|
}
|
|
335
351
|
],
|
|
336
|
-
"description": "Path to an SSL key or content of an SSL key."
|
|
352
|
+
"description": "Path to an SSL key or content of an SSL key. Deprecated, use the `server.options.key` option."
|
|
337
353
|
},
|
|
338
354
|
"pfx": {
|
|
339
355
|
"anyOf": [
|
|
@@ -361,12 +377,12 @@
|
|
|
361
377
|
"instanceof": "Buffer"
|
|
362
378
|
}
|
|
363
379
|
],
|
|
364
|
-
"description": "Path to an SSL pfx file or content of an SSL pfx file."
|
|
380
|
+
"description": "Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the `server.options.pfx` option."
|
|
365
381
|
}
|
|
366
382
|
}
|
|
367
383
|
}
|
|
368
384
|
],
|
|
369
|
-
"description": "Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
|
|
385
|
+
"description": "Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option.",
|
|
370
386
|
"link": "https://webpack.js.org/configuration/dev-server/#devserverhttps"
|
|
371
387
|
},
|
|
372
388
|
"HeaderObject": {
|
|
@@ -470,12 +486,12 @@
|
|
|
470
486
|
},
|
|
471
487
|
"OnAfterSetupMiddleware": {
|
|
472
488
|
"instanceof": "Function",
|
|
473
|
-
"description": "Provides the ability to execute a custom function and apply custom middleware(s) after all other middlewares.",
|
|
489
|
+
"description": "Provides the ability to execute a custom function and apply custom middleware(s) after all other middlewares. Deprecated: please use the 'setupMiddlewares' option.",
|
|
474
490
|
"link": "https://webpack.js.org/configuration/dev-server/#devserveronaftersetupmiddleware"
|
|
475
491
|
},
|
|
476
492
|
"OnBeforeSetupMiddleware": {
|
|
477
493
|
"instanceof": "Function",
|
|
478
|
-
"description": "Provides the ability to execute a custom function and apply custom middleware(s) prior to all other middlewares.",
|
|
494
|
+
"description": "Provides the ability to execute a custom function and apply custom middleware(s) prior to all other middlewares. Deprecated: please use the 'setupMiddlewares' option.",
|
|
479
495
|
"link": "https://webpack.js.org/configuration/dev-server/#devserveronbeforesetupmiddleware"
|
|
480
496
|
},
|
|
481
497
|
"OnListening": {
|
|
@@ -564,7 +580,8 @@
|
|
|
564
580
|
},
|
|
565
581
|
{
|
|
566
582
|
"type": "string",
|
|
567
|
-
"minLength": 1
|
|
583
|
+
"minLength": 1,
|
|
584
|
+
"description": "Open specified browser. Deprecated: please use '--open-app-name'."
|
|
568
585
|
}
|
|
569
586
|
],
|
|
570
587
|
"description": "Open specified browser."
|
|
@@ -615,6 +632,222 @@
|
|
|
615
632
|
"description": "Allows to proxy requests, can be useful when you have a separate API backend development server and you want to send API requests on the same domain.",
|
|
616
633
|
"link": "https://webpack.js.org/configuration/dev-server/#devserverproxy"
|
|
617
634
|
},
|
|
635
|
+
"Server": {
|
|
636
|
+
"anyOf": [
|
|
637
|
+
{
|
|
638
|
+
"$ref": "#/definitions/ServerEnum"
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
"$ref": "#/definitions/ServerString"
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
"$ref": "#/definitions/ServerObject"
|
|
645
|
+
}
|
|
646
|
+
],
|
|
647
|
+
"link": "https://webpack.js.org/configuration/dev-server/#devserverserver",
|
|
648
|
+
"description": "Allows to set server and options (by default 'http')."
|
|
649
|
+
},
|
|
650
|
+
"ServerType": {
|
|
651
|
+
"enum": ["http", "https", "spdy"]
|
|
652
|
+
},
|
|
653
|
+
"ServerEnum": {
|
|
654
|
+
"enum": ["http", "https", "spdy"],
|
|
655
|
+
"cli": {
|
|
656
|
+
"exclude": true
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
"ServerString": {
|
|
660
|
+
"type": "string",
|
|
661
|
+
"minLength": 1,
|
|
662
|
+
"cli": {
|
|
663
|
+
"exclude": true
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
"ServerObject": {
|
|
667
|
+
"type": "object",
|
|
668
|
+
"properties": {
|
|
669
|
+
"type": {
|
|
670
|
+
"anyOf": [
|
|
671
|
+
{
|
|
672
|
+
"$ref": "#/definitions/ServerType"
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
"$ref": "#/definitions/ServerString"
|
|
676
|
+
}
|
|
677
|
+
]
|
|
678
|
+
},
|
|
679
|
+
"options": {
|
|
680
|
+
"$ref": "#/definitions/ServerOptions"
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
"additionalProperties": false
|
|
684
|
+
},
|
|
685
|
+
"ServerOptions": {
|
|
686
|
+
"type": "object",
|
|
687
|
+
"additionalProperties": true,
|
|
688
|
+
"properties": {
|
|
689
|
+
"passphrase": {
|
|
690
|
+
"type": "string",
|
|
691
|
+
"description": "Passphrase for a pfx file."
|
|
692
|
+
},
|
|
693
|
+
"requestCert": {
|
|
694
|
+
"type": "boolean",
|
|
695
|
+
"description": "Request for an SSL certificate."
|
|
696
|
+
},
|
|
697
|
+
"ca": {
|
|
698
|
+
"anyOf": [
|
|
699
|
+
{
|
|
700
|
+
"type": "array",
|
|
701
|
+
"items": {
|
|
702
|
+
"anyOf": [
|
|
703
|
+
{
|
|
704
|
+
"type": "string"
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
"instanceof": "Buffer"
|
|
708
|
+
}
|
|
709
|
+
]
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
"type": "string"
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
"instanceof": "Buffer"
|
|
717
|
+
}
|
|
718
|
+
],
|
|
719
|
+
"description": "Path to an SSL CA certificate or content of an SSL CA certificate."
|
|
720
|
+
},
|
|
721
|
+
"cacert": {
|
|
722
|
+
"anyOf": [
|
|
723
|
+
{
|
|
724
|
+
"type": "array",
|
|
725
|
+
"items": {
|
|
726
|
+
"anyOf": [
|
|
727
|
+
{
|
|
728
|
+
"type": "string"
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
"instanceof": "Buffer"
|
|
732
|
+
}
|
|
733
|
+
]
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
"type": "string"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
"instanceof": "Buffer"
|
|
741
|
+
}
|
|
742
|
+
],
|
|
743
|
+
"description": "Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option."
|
|
744
|
+
},
|
|
745
|
+
"cert": {
|
|
746
|
+
"anyOf": [
|
|
747
|
+
{
|
|
748
|
+
"type": "array",
|
|
749
|
+
"items": {
|
|
750
|
+
"anyOf": [
|
|
751
|
+
{
|
|
752
|
+
"type": "string"
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
"instanceof": "Buffer"
|
|
756
|
+
}
|
|
757
|
+
]
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
"type": "string"
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
"instanceof": "Buffer"
|
|
765
|
+
}
|
|
766
|
+
],
|
|
767
|
+
"description": "Path to an SSL certificate or content of an SSL certificate."
|
|
768
|
+
},
|
|
769
|
+
"crl": {
|
|
770
|
+
"anyOf": [
|
|
771
|
+
{
|
|
772
|
+
"type": "array",
|
|
773
|
+
"items": {
|
|
774
|
+
"anyOf": [
|
|
775
|
+
{
|
|
776
|
+
"type": "string"
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
"instanceof": "Buffer"
|
|
780
|
+
}
|
|
781
|
+
]
|
|
782
|
+
}
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
"type": "string"
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
"instanceof": "Buffer"
|
|
789
|
+
}
|
|
790
|
+
],
|
|
791
|
+
"description": "Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists)."
|
|
792
|
+
},
|
|
793
|
+
"key": {
|
|
794
|
+
"anyOf": [
|
|
795
|
+
{
|
|
796
|
+
"type": "array",
|
|
797
|
+
"items": {
|
|
798
|
+
"anyOf": [
|
|
799
|
+
{
|
|
800
|
+
"type": "string"
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
"instanceof": "Buffer"
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
"type": "object",
|
|
807
|
+
"additionalProperties": true
|
|
808
|
+
}
|
|
809
|
+
]
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
"type": "string"
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
"instanceof": "Buffer"
|
|
817
|
+
}
|
|
818
|
+
],
|
|
819
|
+
"description": "Path to an SSL key or content of an SSL key."
|
|
820
|
+
},
|
|
821
|
+
"pfx": {
|
|
822
|
+
"anyOf": [
|
|
823
|
+
{
|
|
824
|
+
"type": "array",
|
|
825
|
+
"items": {
|
|
826
|
+
"anyOf": [
|
|
827
|
+
{
|
|
828
|
+
"type": "string"
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
"instanceof": "Buffer"
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
"type": "object",
|
|
835
|
+
"additionalProperties": true
|
|
836
|
+
}
|
|
837
|
+
]
|
|
838
|
+
}
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
"type": "string"
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
"instanceof": "Buffer"
|
|
845
|
+
}
|
|
846
|
+
],
|
|
847
|
+
"description": "Path to an SSL pfx file or content of an SSL pfx file."
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
},
|
|
618
851
|
"SetupExitSignals": {
|
|
619
852
|
"type": "boolean",
|
|
620
853
|
"description": "Allows to close dev server and exit the process on SIGINT and SIGTERM signals (enabled by default for CLI).",
|
|
@@ -623,6 +856,11 @@
|
|
|
623
856
|
"exclude": true
|
|
624
857
|
}
|
|
625
858
|
},
|
|
859
|
+
"SetupMiddlewares": {
|
|
860
|
+
"instanceof": "Function",
|
|
861
|
+
"description": "Provides the ability to execute a custom function and apply custom middleware(s).",
|
|
862
|
+
"link": "https://webpack.js.org/configuration/dev-server/#devserversetupmiddlewares"
|
|
863
|
+
},
|
|
626
864
|
"Static": {
|
|
627
865
|
"anyOf": [
|
|
628
866
|
{
|
|
@@ -759,10 +997,13 @@
|
|
|
759
997
|
"type": "string",
|
|
760
998
|
"minLength": 1
|
|
761
999
|
}
|
|
762
|
-
]
|
|
1000
|
+
],
|
|
1001
|
+
"description": "Path(s) of globs/directories/files to watch for file changes."
|
|
763
1002
|
},
|
|
764
1003
|
"options": {
|
|
765
1004
|
"type": "object",
|
|
1005
|
+
"description": "Configure advanced options for watching. See the chokidar documentation for the possible options.",
|
|
1006
|
+
"link": "https://github.com/paulmillr/chokidar#api",
|
|
766
1007
|
"additionalProperties": true
|
|
767
1008
|
}
|
|
768
1009
|
},
|
|
@@ -790,22 +1031,30 @@
|
|
|
790
1031
|
"description": "Allows to set web socket server and options (by default 'ws').",
|
|
791
1032
|
"link": "https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver"
|
|
792
1033
|
},
|
|
1034
|
+
"WebSocketServerType": {
|
|
1035
|
+
"enum": ["sockjs", "ws"]
|
|
1036
|
+
},
|
|
793
1037
|
"WebSocketServerEnum": {
|
|
794
|
-
"
|
|
1038
|
+
"anyOf": [
|
|
1039
|
+
{
|
|
1040
|
+
"enum": [false]
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
"$ref": "#/definitions/WebSocketServerType"
|
|
1044
|
+
}
|
|
1045
|
+
],
|
|
1046
|
+
"description": "Deprecated: please use '--web-socket-server-type' option."
|
|
795
1047
|
},
|
|
796
1048
|
"WebSocketServerFunction": {
|
|
797
1049
|
"instanceof": "Function"
|
|
798
1050
|
},
|
|
799
1051
|
"WebSocketServerObject": {
|
|
800
1052
|
"type": "object",
|
|
801
|
-
"cli": {
|
|
802
|
-
"exclude": true
|
|
803
|
-
},
|
|
804
1053
|
"properties": {
|
|
805
1054
|
"type": {
|
|
806
1055
|
"anyOf": [
|
|
807
1056
|
{
|
|
808
|
-
"$ref": "#/definitions/
|
|
1057
|
+
"$ref": "#/definitions/WebSocketServerType"
|
|
809
1058
|
},
|
|
810
1059
|
{
|
|
811
1060
|
"$ref": "#/definitions/WebSocketServerString"
|
|
@@ -817,7 +1066,10 @@
|
|
|
817
1066
|
},
|
|
818
1067
|
"options": {
|
|
819
1068
|
"type": "object",
|
|
820
|
-
"additionalProperties": true
|
|
1069
|
+
"additionalProperties": true,
|
|
1070
|
+
"cli": {
|
|
1071
|
+
"exclude": true
|
|
1072
|
+
}
|
|
821
1073
|
}
|
|
822
1074
|
},
|
|
823
1075
|
"additionalProperties": false
|
|
@@ -889,9 +1141,15 @@
|
|
|
889
1141
|
"proxy": {
|
|
890
1142
|
"$ref": "#/definitions/Proxy"
|
|
891
1143
|
},
|
|
1144
|
+
"server": {
|
|
1145
|
+
"$ref": "#/definitions/Server"
|
|
1146
|
+
},
|
|
892
1147
|
"setupExitSignals": {
|
|
893
1148
|
"$ref": "#/definitions/SetupExitSignals"
|
|
894
1149
|
},
|
|
1150
|
+
"setupMiddlewares": {
|
|
1151
|
+
"$ref": "#/definitions/SetupMiddlewares"
|
|
1152
|
+
},
|
|
895
1153
|
"static": {
|
|
896
1154
|
"$ref": "#/definitions/Static"
|
|
897
1155
|
},
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/** @typedef {import("../Server").ClientConnection} ClientConnection */
|
|
4
|
+
|
|
3
5
|
// base class that users should extend if they are making their own
|
|
4
6
|
// server implementation
|
|
5
7
|
module.exports = class BaseServer {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import("../Server")} server
|
|
10
|
+
*/
|
|
6
11
|
constructor(server) {
|
|
12
|
+
/** @type {import("../Server")} */
|
|
7
13
|
this.server = server;
|
|
14
|
+
|
|
15
|
+
/** @type {ClientConnection[]} */
|
|
8
16
|
this.clients = [];
|
|
9
17
|
}
|
|
10
18
|
};
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
/* eslint-disable
|
|
4
|
-
class-methods-use-this
|
|
5
|
-
*/
|
|
6
3
|
const sockjs = require("sockjs");
|
|
7
4
|
const BaseServer = require("./BaseServer");
|
|
8
5
|
|
|
6
|
+
/** @typedef {import("../Server").WebSocketServerConfiguration} WebSocketServerConfiguration */
|
|
7
|
+
/** @typedef {import("../Server").ClientConnection} ClientConnection */
|
|
8
|
+
|
|
9
9
|
// Workaround for sockjs@~0.3.19
|
|
10
10
|
// sockjs will remove Origin header, however Origin header is required for checking host.
|
|
11
11
|
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
|
|
12
12
|
{
|
|
13
|
+
// @ts-ignore
|
|
13
14
|
const SockjsSession = require("sockjs/lib/transport").Session;
|
|
14
15
|
const decorateConnection = SockjsSession.prototype.decorateConnection;
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @param {import("http").IncomingMessage} req
|
|
19
|
+
*/
|
|
16
20
|
// eslint-disable-next-line func-names
|
|
17
21
|
SockjsSession.prototype.decorateConnection = function (req) {
|
|
18
22
|
decorateConnection.call(this, req);
|
|
@@ -31,6 +35,9 @@ const BaseServer = require("./BaseServer");
|
|
|
31
35
|
|
|
32
36
|
module.exports = class SockJSServer extends BaseServer {
|
|
33
37
|
// options has: error (function), debug (function), server (http/s server), path (string)
|
|
38
|
+
/**
|
|
39
|
+
* @param {import("../Server")} server
|
|
40
|
+
*/
|
|
34
41
|
constructor(server) {
|
|
35
42
|
super(server);
|
|
36
43
|
|
|
@@ -38,6 +45,10 @@ module.exports = class SockJSServer extends BaseServer {
|
|
|
38
45
|
// Use provided up-to-date sockjs-client
|
|
39
46
|
sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js",
|
|
40
47
|
// Default logger is very annoy. Limit useless logs.
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} severity
|
|
50
|
+
* @param {string} line
|
|
51
|
+
*/
|
|
41
52
|
log: (severity, line) => {
|
|
42
53
|
if (severity === "error") {
|
|
43
54
|
this.server.logger.error(line);
|
|
@@ -49,6 +60,10 @@ module.exports = class SockJSServer extends BaseServer {
|
|
|
49
60
|
},
|
|
50
61
|
});
|
|
51
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @param {import("sockjs").ServerOptions & { path?: string }} options
|
|
65
|
+
* @returns {string | undefined}
|
|
66
|
+
*/
|
|
52
67
|
const getPrefix = (options) => {
|
|
53
68
|
if (typeof options.prefix !== "undefined") {
|
|
54
69
|
return options.prefix;
|
|
@@ -57,23 +72,41 @@ module.exports = class SockJSServer extends BaseServer {
|
|
|
57
72
|
return options.path;
|
|
58
73
|
};
|
|
59
74
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
const options = {
|
|
76
|
+
.../** @type {WebSocketServerConfiguration} */
|
|
77
|
+
(this.server.options.webSocketServer).options,
|
|
78
|
+
prefix: getPrefix(
|
|
79
|
+
/** @type {NonNullable<WebSocketServerConfiguration["options"]>} */
|
|
80
|
+
(
|
|
81
|
+
/** @type {WebSocketServerConfiguration} */
|
|
82
|
+
(this.server.options.webSocketServer).options
|
|
83
|
+
)
|
|
84
|
+
),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
this.implementation.installHandlers(
|
|
88
|
+
/** @type {import("http").Server} */ (this.server.server),
|
|
89
|
+
options
|
|
90
|
+
);
|
|
64
91
|
|
|
65
92
|
this.implementation.on("connection", (client) => {
|
|
93
|
+
// @ts-ignore
|
|
66
94
|
// Implement the the same API as for `ws`
|
|
67
95
|
client.send = client.write;
|
|
96
|
+
// @ts-ignore
|
|
68
97
|
client.terminate = client.close;
|
|
69
98
|
|
|
70
|
-
this.clients.push(client);
|
|
99
|
+
this.clients.push(/** @type {ClientConnection} */ (client));
|
|
71
100
|
|
|
72
101
|
client.on("close", () => {
|
|
73
|
-
this.clients.splice(
|
|
102
|
+
this.clients.splice(
|
|
103
|
+
this.clients.indexOf(/** @type {ClientConnection} */ (client)),
|
|
104
|
+
1
|
|
105
|
+
);
|
|
74
106
|
});
|
|
75
107
|
});
|
|
76
108
|
|
|
109
|
+
// @ts-ignore
|
|
77
110
|
this.implementation.close = (callback) => {
|
|
78
111
|
callback();
|
|
79
112
|
};
|