question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't use hard-coded localhost for websocket

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
davidhao3300commented, Sep 7, 2022

Looks good to me, thank you!

1reaction
davidhao3300commented, Sep 7, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket connection to 'ws://localhost:3000/ws' failed
Basic React App doesn't work because the websocket connection appears to be hardcoded to port 3000. Part of this appears to be related...
Read more >
javascript - Failed: Error in connection establishment: net ...
Firstly, I would try a non-secure websocket connection. So remove one of the s 's from the connection address: conn = new WebSocket('ws://localhost:8080');....
Read more >
WebSockets By Hand – Complete Intro to Realtime
We are going to first just try to receive any connection from anyone. That's how sockets work: they make a normal TCP/IP connection...
Read more >
.NET 6 Hot Reload and "Refused to connect to ws ...
Let's do just wss:, only in Development. Now, if I'm using both CSPs and WebSockets (ws:, wss:) in Production, I'll need to be...
Read more >
WebSockets not Bound by SOP and CORS? Does this ...
While the client uses an HTTP handshake to establish a WebSocket ... and a Cross-Origin WS Client (hosted on localhost:9000) — which utilize ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found