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

Don't use hard-coded localhost for websocket #258

Closed
davidhao3300 opened this issue Sep 6, 2022 · 6 comments
Closed

Don't use hard-coded localhost for websocket #258

davidhao3300 opened this issue Sep 6, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@davidhao3300
Copy link

Describe the bug

localhost is hard-coded here: https://github.com/nvh95/jest-preview/blob/v0.3.1/cli/server/ws-client.js#L4

This makes remote development a little more finicky. I'm running jest-preview in a remote server, and want to use my laptop's browser to visit the jest preview dashboard. Right now the dashboard loads fine, but since the websocket client tries to hit localhost, the auto-reloading doesn't work. I haven't tried it, but I believe a SSH tunnel would work around the issue, but would prefer not have to set that up.

I manually replaced localhost with my remote server's address, and things worked great

Screenshots

N/A

Reproduce

On a remote server with ports 3336 and 3337 available, run yarn jest-preview. Attempt to visit the remote IP at port 3336. Note that the JS console says that it tries to reach localhost:3337

Expected behavior

I think the simplest and almost-strictly-better than current state is to use the browser host (window.host or whatever) as the hostname. For people using localhost, things will continue to work like before, while those using non-localhost should now automatically work, assuming that port 3337 is reachable.

There is an edge case for people who use 3336 with a remote hostname, but need a localhost 3337 for some reason...

Environment (please complete the following information)

Running yarn jest-preview on a remote server, 0.3.1

@davidhao3300 davidhao3300 added the bug Something isn't working label Sep 6, 2022
@nvh95
Copy link
Owner

nvh95 commented Sep 7, 2022

Hi @davidhao3300

Thanks for your report. I published version v0.3.2-alpha.0 to fix this. Can you try again with that version? I will incorporate a few other updates and release them all at once soon.

npm install --save-dev jest-preview@v0.3.2-alpha.0

There is an edge case for people who use 3336 with a remote hostname, but need a localhost 3337 for some reason...

For now the PORT for jest-preview is 3336 and the port for socket connection is PORT+1 (e.g: 3337). Users can customize it my specify a custom port (e.g: PORT=3761 npm run jest-preview). I would like to find available ports automatically but haven't done yet. For now it's a low priority and we are happy to have the help of the community.

@davidhao3300
Copy link
Author

I will give the new version a try today, thank you. The diff does look good to me!

@nvh95
Copy link
Owner

nvh95 commented Sep 7, 2022

@davidhao3300 Thanks. I am looking forward to your confirmation.

@davidhao3300
Copy link
Author

Looks good to me, thank you!

@nvh95
Copy link
Owner

nvh95 commented Sep 8, 2022

@all-contributors please add @davidhao3300 for bug

@allcontributors
Copy link
Contributor

@nvh95

I've put up a pull request to add @davidhao3300! 🎉

@nvh95 nvh95 closed this as completed Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants