2

I have setup a websocket server in Spring which uses a WebSocketConfig as follows:

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry.addHandler(webSocketHandler(), "/websocket").setAllowedOrigins("*");
}
@Bean
public WebSocketHandler webSocketHandler() {
    return new ServerWebSocketHandler();
}

}

My setup entails establishing a websocket connection with the server from a website. The website is running locally (e.g. http://localhost:5555) and is using the Websocket API. I am able to establish a connection and send/receive messages only if setAllowedOrigins("*"). I have tried, for example:

  • setAllowedOrigins("http://localhost:5555")
  • setAllowedOrigins("http://127.0.0.1")
  • etc...

However, only "*" allows the connection be established. How can I narrow the allowed CORS origins?

jwdomes
  • 21

0 Answers0