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

reload-client.js via /reload/reload.js fails when Node server is listening on port 80 #126

Closed
superhawk610 opened this issue Jul 11, 2017 · 11 comments · Fixed by #128
Closed
Labels

Comments

@superhawk610
Copy link
Contributor

In the latest stable build of Chrome, window.location.origin doesn't include a port number when the port is 80, thus the regex for setting socketUrl in reload-client.js fails to match and produces an error when attempting to open a new WebSocket on the client's side.

I'm sure this isn't a common issue as most Node development is done on ports other than 80, but it sure gave me a headache for 20 minutes.

@ghost
Copy link

ghost commented Jul 12, 2017

What error does it give?

@superhawk610
Copy link
Contributor Author

Here's the error:
image

Which leads to this line in the trace:
image

socketUrl is set at this line:
image

Logging the value of window.location.origin shows that it is http://localhost, which would fail to match that regex as it has no colon or port number following. The same thing happens at 127.0.0.1, as window.location.origin resolves to http://127.0.0.1, again with no colon or port number.

@alallier
Copy link
Owner

Very nice catch. Feel free to send PR otherwise we will get this patched soon

@meszaros-lajos-gyorgy
Copy link

So what is the temporary solution until the fix is released? Should I run my server on different port?

@meszaros-lajos-gyorgy
Copy link

Answering to my previous question: Yes, just run the code on port 3000 or something, but not on 80.

@ghost
Copy link

ghost commented Jul 20, 2017

Should I add a note on README.md explaining this? I can remove it when the fix is released.

@alallier
Copy link
Owner

@meszaros-lajos-gyorgy yes for now. I will get the fix up now. @Yamboy1 that should answer your question too.

@alallier
Copy link
Owner

alallier commented Jul 20, 2017

@meszaros-lajos-gyorgy should be all set. Published to npm

@meszaros-lajos-gyorgy
Copy link

Thank you!

@johhansantana
Copy link

I'm still getting this error.

Running the server on port 3000

...

const server = http.createServer(app);

reload(app);

server.listen(3000, () => console.log("Example app listening on port 3000!"));

and I have copied the client javascript

<script src="/src/js/reload-client.js" ></script>
VM746:164 Uncaught DOMException: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'http' is not allowed.
    at new WrappedWebSocket (<anonymous>:164:21)
    at http://localhost:3000/src/js/reload-client.js:94:16

@alallier
Copy link
Owner

alallier commented Apr 24, 2018

@johhansantana you are not including your JS script tag correctly. It should look like this <script src="/reload/reload.js"></script>. Reload creates a route and serves the client side file initialized for you. You should not require it directly. Give that tweak a try, refer to the example, and let me know if you still have trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants