Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds HOST and PORT env variables to react app so websocket #1588

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions packages/react-dev-utils/webpackHotDevClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,13 @@ 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,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
var connection = new SockJS(url.format({
protocol: window.location.protocol,
hostname: process.env.HOST || window.location.hostname,
port: process.env.PORT || window.location.port,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node'
}));

// Unlike WebpackDevServer client, we won't try to reconnect
// to avoid spamming the console. Disconnect usually happens
Expand Down
5 changes: 5 additions & 0 deletions packages/react-scripts/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ function getClientEnvironment(publicUrl) {
// 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,
// 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
Expand Down