From acc5ab13da20d777012f53578b76266d5521cff0 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 14 Nov 2018 11:09:40 +0100 Subject: [PATCH 1/4] Fixed not working websocket proxy (fix: #5280) Fixed that websockets, e.g. via Socket.io won't be proxied through the HTTP Proxy. --- packages/react-dev-utils/WebpackDevServerUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 0a3e233e641..2767e772da0 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -324,6 +324,7 @@ function prepareProxy(proxy, appPublicFolder) { // If this heuristic doesn’t work well for you, use a custom `proxy` object. context: function(pathname, req) { return ( + req.upgrade || req.method !== 'GET' || (mayProxy(pathname) && req.headers.accept && From e29fac9bd63842bca1256b3b805c35ab2642e992 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 23 Nov 2018 08:35:29 +0100 Subject: [PATCH 2/4] Reworked proxy context logic --- packages/react-dev-utils/WebpackDevServerUtils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 2767e772da0..5ca57bc92fb 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -324,7 +324,10 @@ function prepareProxy(proxy, appPublicFolder) { // If this heuristic doesn’t work well for you, use a custom `proxy` object. context: function(pathname, req) { return ( - req.upgrade || + (!pathname.startsWith("/sockjs-node") && + req.upgrade && + req.headers.upgrade && + req.headers.upgrade.toLowerCase() === 'websocket') || req.method !== 'GET' || (mayProxy(pathname) && req.headers.accept && From ecb99e35a732225e94f21e99507f8005286301b8 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 25 Feb 2019 10:48:51 +0100 Subject: [PATCH 3/4] added trailing slash to trigger CI --- packages/react-dev-utils/WebpackDevServerUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 5ca57bc92fb..26779910b6a 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -324,7 +324,7 @@ function prepareProxy(proxy, appPublicFolder) { // If this heuristic doesn’t work well for you, use a custom `proxy` object. context: function(pathname, req) { return ( - (!pathname.startsWith("/sockjs-node") && + (!pathname.startsWith("/sockjs-node/") && req.upgrade && req.headers.upgrade && req.headers.upgrade.toLowerCase() === 'websocket') || From 42e34d92cd73903d639e60c1aac15682ec49be1b Mon Sep 17 00:00:00 2001 From: Brody McKee Date: Thu, 14 Mar 2019 07:31:42 +0100 Subject: [PATCH 4/4] docs: added comment to describe the change Co-Authored-By: mxschmitt --- packages/react-dev-utils/WebpackDevServerUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 26779910b6a..df428313cca 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -324,6 +324,7 @@ function prepareProxy(proxy, appPublicFolder) { // If this heuristic doesn’t work well for you, use a custom `proxy` object. context: function(pathname, req) { return ( + // Resolves an issue with WebSocket (#5280). (!pathname.startsWith("/sockjs-node/") && req.upgrade && req.headers.upgrade &&