halfzebra / create-elm-app

🍃 Create Elm apps with zero configuration
MIT License
1.69k stars 147 forks source link

[Question] How to prevent rewrite of websocket url to "sockjs-node/[random]/[random]/" #593

Open perty opened 3 years ago

perty commented 3 years ago

Is this a bug report?

No, this is a call for help.

I have a small script to bridge between Elm and WebSockets. I have done this in other Elm apps which do not use create-elm-app without problem. However, when I use create-elm-app, the url I provide gets rewritten.

const ws = new WebSocket(protocol + "//" + host + "/websocket");

Results in: WebSocket connection to 'ws://localhost:3000/sockjs-node/631/03d4psaf/websocket' failed: WebSocket is closed before the connection is established.

As can be seen, something is interfering with setting up the WebSocket. The url is prepended with a partially random string.

After googling, I suspect this has something to do with Webpack which uses SockJs for hot reloading. This might be therefore be unsolvable, it is just how JavaScript works, if someone decides to intercept something, then everyone is hit.

But if I am wrong, I really like to know how to avoid the URL rewrite.