title: WebSocket with Spring Boot and JavaScript
body: <p>This is my simple attempt to create a WebSocket channel between a JavaScript client and a Java server.</p>
  <pre><code>// java websocket server configuration with spring boot
  // server port: 8080 set in the &quot;application.yml&quot;
  
  @Configuration
  @EnableWebSocketMessageBroker
  public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer{
      
      @Override
      public void registerStompEndpoints(StompEndpointRegistry registry) {
          registry.addEndpoint(&quot;/websocket&quot;)
                  .setAllowedOrigins(&quot;*&quot;)
                  .withSockJS();
      }
  
      @Override
      public void configureMessageBroker(MessageBrokerRegistry registry) {                
          registry.setApplicationDestinationPrefixes(&quot;/app&quot;)
                  .enableSimpleBroker(&quot;/notification&quot;);
      }   
  } 
  </code></pre>
  <pre><code>// js websocket client configuration with &quot;webstomp-client&quot;
  
  import webstomp from 'webstomp-client';
  
  const connection = new WebSocket('ws://localhost:8080/websocket');
  const stompClient = webstomp.over(connection);
  stompClient.connect(()=&gt;{
    stompClient.subscribe('/app/notification', () =&gt; console.log('Connection established with server'));
  });
  </code></pre>
  <p>The console shows the following:</p>
  <blockquote>
  <p>WebSocket connection to 'ws://localhost:8080/websocket' failed: Error during WebSocket handshake: Unexpected response code: 200</p>
  </blockquote>
  <p>I looked at a lot of other posts, and most of them had to do with allowing the origin. I have tried setting the origin to <code>localhost</code> as well as the local IP address, but without success.</p>
  <p>What am I missing? Any help would be tremendous.</p>
  <p><em><strong>Edit:</strong></em> The client is created with <code>create-react-app</code>, if that's relevant.</p>
  <p><em><strong>Edit:</strong></em> The client is on: <code>http:localhost:3000</code>, the server is on: <code>http:localhost:8080</code>.</p>