Skip to content

Commit a34d066

Browse files
committed
Ensure proxy heuristic works for WebSocket requests on Chrome
1 parent daf0814 commit a34d066

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/react-dev-utils/WebpackDevServerUtils.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,19 @@ function prepareProxy(proxy, appPublicFolder, servedPathname) {
359359
// We use a heuristic: We want to proxy all the requests that are not meant
360360
// for static assets and as all the requests for static assets will be using
361361
// `GET` method, we can proxy all non-`GET` requests.
362-
// For `GET` requests, if request `accept`s text/html, we pick /index.html.
362+
// For `GET` requests, if request `Accept`s text/html, we pick /index.html.
363363
// Modern browsers include text/html into `accept` header when navigating.
364364
// However API calls like `fetch()` won’t generally accept text/html.
365+
// Some browsers don't set an `Accept` header on WebSocket upgrade requests,
366+
// so we also have a check for those to make sure they are still proxied.
365367
// If this heuristic doesn’t work well for you, use `src/setupProxy.js`.
366368
context: function (pathname, req) {
367369
return (
368370
req.method !== 'GET' ||
369371
(mayProxy(pathname) &&
370-
req.headers.accept &&
371-
req.headers.accept.indexOf('text/html') === -1)
372+
((req.headers.accept &&
373+
req.headers.accept.indexOf('text/html') === -1) ||
374+
(req.headers.upgrade && req.headers.upgrade === 'websocket')))
372375
);
373376
},
374377
onProxyReq: proxyReq => {

0 commit comments

Comments
 (0)