@@ -12,9 +12,21 @@ class ErrorOverlayPlugin {
12
12
const devServerEnabled = ! ! compiler . options . devServer
13
13
const sockOptions = { }
14
14
if ( devServerEnabled ) {
15
- sockOptions . sockHost = compiler . options . devServer . sockHost
16
- sockOptions . sockPath = compiler . options . devServer . sockPath
17
- sockOptions . sockPort = compiler . options . devServer . sockPort
15
+ // In the webpack config it's possible to override the websocket server's
16
+ // connect URL for clients that need to connect through a proxy or other means.
17
+ //
18
+ // Use a webSocketURL config if present, otherwise default to the same address
19
+ // as the devServer:
20
+ sockOptions . sockHost =
21
+ compiler . options . devServer . client ?. webSocketURL ?. hostname ||
22
+ compiler . options . devServer . host
23
+ sockOptions . sockPath =
24
+ compiler . options . devServer . client ?. webSocketURL ?. pathname ||
25
+ compiler . options . devServer . webSocketServer ?. options . path ||
26
+ '/ws'
27
+ sockOptions . sockPort =
28
+ compiler . options . devServer . client ?. webSocketURL ?. port ||
29
+ compiler . options . devServer . port
18
30
}
19
31
20
32
compiler . hooks . entryOption . tap ( className , ( context , entry ) => {
@@ -23,12 +35,13 @@ class ErrorOverlayPlugin {
23
35
24
36
compiler . hooks . afterResolvers . tap ( className , ( { options } ) => {
25
37
if ( devServerEnabled ) {
26
- const originalBefore = options . devServer . before
27
- options . devServer . before = ( app , server ) => {
28
- if ( originalBefore ) {
29
- originalBefore ( app , server , compiler )
38
+ const originalOnBeforeSetupMiddleware =
39
+ options . devServer . onBeforeSetupMiddleware
40
+ options . devServer . onBeforeSetupMiddleware = ( devServer ) => {
41
+ if ( originalOnBeforeSetupMiddleware ) {
42
+ originalOnBeforeSetupMiddleware ( devServer )
30
43
}
31
- app . use ( errorOverlayMiddleware ( ) )
44
+ devServer . app . use ( errorOverlayMiddleware ( ) )
32
45
}
33
46
}
34
47
} )
0 commit comments