SvenKirschbaum / react-stomp-hooks

This repository contain a react library which enables simple access to stomp subscriptions via hooks.
MIT License
59 stars 12 forks source link

Problem with CORS credentials #29

Closed akiselevych closed 5 months ago

akiselevych commented 5 months ago

Hello. I have a problem with CORS. I configured my spring boot app and allow @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") .withSockJS(); } But still receive CORS Error

image

This is how it looks in react const HomePage = () => { return ( <StompSessionProvider url={"http://localhost:9000/ws"}> <TestComp/> </StompSessionProvider> ) } const TestComp = () => { useSubscription("/2/queue/messages", (message) => console.log(message)); return ( <p></p> ) }

I also tried to allow strictly one origin, but it didnt help too (

SvenKirschbaum commented 5 months ago

Hello!

As far as i can tell based on the snippets you provided this setup should work, and I am personally using an nearly identical setup in multiple apps myself. In fact the Example Project connects to a (Cross Origin) Backend which is implemented in Spring this way, you can find its source code here.

Please first check which headers are returned by spring in the failing request, and secondly please also check if the request path is routed to the Spring stomp Service correctly by opening the URL with your browser. The Response should look like this.

akiselevych commented 5 months ago

Thank you !