Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !6724

Use current script URL when connecting to WS server.

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/n6g7/custom-host-port into main Mar 27, 2019
  • Overview 17
  • Commits 1
  • Pipelines 0
  • Changes 1

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.
  • 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 the curl command above fixes it.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/n6g7/custom-host-port