In vertx example websocket url hardcoded in html as localhost:
socket = new WebSocket("ws://localhost:8080/myapp");
Which is the correct, "production" way for specifying the remote address in html, especially in vertx?
This is not specific to Vert.x at all, but you can use window.location.host
to get the current (page) host:
socket = new WebSocket("ws://" + window.location.host + "/myapp");
Based on environment you can load websocket :
if(location.origin.includes("localhost")){
this.wsUrl = "http://localhost:8080/myapp";
}else{
this.wsUrl = location.origin +"/myapp";
}
socket = new WebSocket(this.wsUrl);
you can use sockjs-client to open websocket : sockjs-client
Have a look at this example . I hope this will help you :)