Created by: n6g7
Hey,
In this PR I added support for connecting to a WS server on a different origin than the one of the current document (useful in cases where the app HTML isn't served by the CRA dev server). See https://github.com/facebook/create-react-app/issues/4468 for more info.
To do this I used the same approach as WDS: instead of using window.location
in every case, try to use the url of the current script.
To test this feature:
- Test it's still working in the simple case:
- Run
yarn start
- Open http://localhost:3000 in your browser
- Edit
packages/react-scripts/template/src/App.js
and save - See the page hot-reload, as before.
- Run
- Test it's working when serving the HTML from a different port:
- Run
yarn start
- Create a temporary directory:
mkdir tmp
- Get a copy of the app's HTML with links to the CRA dev server:
curl localhost:3000 | sed s_=\"/_=\"http://localhost:3000/_g > index.html
- Run a second test server locally:
python -m http.server 8000
- Open http://localhost:8000 in your browser
- Edit
packages/react-scripts/template/src/App.js
and save - See the page hot-reload, as before
- It might be blank after the reload, that's because the
*.hot-update.js
part of the html is out of date, re-running thecurl
command above fixes it.
- It might be blank after the reload, that's because the
- Run