Skip to content

Commit 37d07b9

Browse files
Enable proxying of websockets, fix #2
1 parent 9ca1f83 commit 37d07b9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

scripts/start.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,23 @@ function addMiddleware(devServer) {
205205
// - /sockjs-node/* (WebpackDevServer uses this for hot reloading)
206206
// Tip: use https://www.debuggex.com/ to visualize the regex
207207
var mayProxy = /^(?!\/(index\.html$|.*\.hot-update\.json$|sockjs-node\/)).*$/;
208-
devServer.use(mayProxy,
209-
// Pass the scope regex both to Express and to the middleware for proxying
210-
// of both HTTP and WebSockets to work without false positives.
211-
httpProxyMiddleware(pathname => mayProxy.test(pathname), {
212-
target: proxy,
213-
logLevel: 'silent',
214-
secure: false,
215-
changeOrigin: true
216-
})
217-
);
208+
209+
// Pass the scope regex both to Express and to the middleware for proxying
210+
// of both HTTP and WebSockets to work without false positives.
211+
var hpm = httpProxyMiddleware(pathname => mayProxy.test(pathname), {
212+
target: proxy,
213+
logLevel: 'silent',
214+
onError: onProxyError(proxy),
215+
secure: false,
216+
changeOrigin: true,
217+
ws: true
218+
});
219+
devServer.use(mayProxy, hpm);
220+
221+
// Listen for the websocket 'upgrade' event and upgrade the connection.
222+
// If this is not done, httpProxyMiddleware will not try to upgrade until
223+
// an initial plain HTTP request is made.
224+
devServer.listeningApp.on('upgrade', hpm.upgrade);
218225
}
219226
// Finally, by now we have certainly resolved the URL.
220227
// It may be /index.html, so let the dev server try serving it again.

0 commit comments

Comments
 (0)