netty-socketio icon indicating copy to clipboard operation
netty-socketio copied to clipboard

Add CORS headers to server

Open Martijnpold opened this issue 5 years ago • 2 comments

Currently our Angular based project is failing to connect to our java socket-io backend. As far as we can see this happens due to the browser rejecting the connection because of an invalid CORS header.

How do you configure these headers to be correct and allow any connection from any IP?

We tried: config.setOrigin(""); config.setOrigin("[full ip]"); config.setOrigin("[full ip]:"); and various mutations similar, none seem to work though

Martijnpold avatar Apr 10 '20 13:04 Martijnpold

Could you try this

config.setOrigin("*");

It adds a wildcard to the 'Access-Control-Allow-Origin' header

pim97 avatar Apr 18 '20 17:04 pim97

Could you try this

config.setOrigin("*");

It adds a wildcard to the 'Access-Control-Allow-Origin' header

does not work

voonic avatar Aug 16 '22 17:08 voonic

I have a same probelem.Is there something way to solve this?

BenanaH avatar Feb 14 '23 03:02 BenanaH

config.setAllowHeaders("*");

yujuncai avatar Feb 14 '23 06:02 yujuncai

Old post but I believe this can also be solved by using the angular proxy configuration (partially an assumption, but I've had similar things with rest api's in dev environments).

More here: https://angular.io/guide/build#proxying-to-a-backend-server

Will close this issue and good luck to anyone reading this.

Martijnpold avatar Mar 27 '23 13:03 Martijnpold