I validated that my websocket works by using Postman, however when I try and use the Javascript WebSocket class to connect from the frontend, I get a WebSocket connection to 'ws://...' failed that does not provide any error or description. I understand that for security reasons the browser does not display a comprehensive error message, however I am unsure what is going on and how to fix it.
Frontend:
ReactDOM.render(<Testing />, document.getElementById('root))
const Testing = () => {
let socket = new WebSocket("ws://localhost:8080/ws-setup/websocket")
return <div>Testing Page</div>
}
Postman: Set type to Raw, add 'ws://localhost:8080/ws-setup/websocket' and click connect. It tells me the connection was established in the messages viewport.
Configuration file in Spring Boot:
@Override
public void configureMessageBroker(final MessageBrokerRegistry config)
{
config.enableSimpleBroker("/branches-ws");
config.setApplicationDestinationPrefixes("/ws");
}
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry)
{
registry
.addEndpoint("/ws-setup")
.setAllowedOrigins("*")
.withSockJS();
}
Why is it not working?