From 532b4636716b3006d848683131f96395e546fc1e Mon Sep 17 00:00:00 2001 From: scisci Date: Sat, 18 Feb 2017 05:04:08 -0500 Subject: [PATCH] Adds HOST and PORT env variables to react app so websocket can use them instead of window.href --- packages/react-dev-utils/webpackHotDevClient.js | 4 ++-- packages/react-scripts/config/env.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 903861a65d1..335f7fd256f 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -139,8 +139,8 @@ function destroyErrorOverlay() { // Connect to WebpackDevServer via a socket. var connection = new SockJS(url.format({ protocol: window.location.protocol, - hostname: window.location.hostname, - port: window.location.port, + hostname: process.env.HOST || window.location.hostname, + port: process.env.PORT || window.location.port, // Hardcoded in WebpackDevServer pathname: '/sockjs-node' })); diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index 168e1e644f1..f02b602cc70 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -29,7 +29,12 @@ function getClientEnvironment(publicUrl) { // For example, . // This should only be used as an escape hatch. Normally you would put // images into the `src` and `import` them in code to get their paths. - 'PUBLIC_URL': publicUrl + 'PUBLIC_URL': publicUrl, + // Useful for allowing the hot dev websocket to connect to the host + // specified in the env file, instead of window.location, which could + // be wrong if the dev server is being proxied. + 'HOST': process.env.HOST || '', + 'PORT': process.env.PORT || '' }); // Stringify all values so we can feed into Webpack DefinePlugin var stringified = {