The-Commit-Company / frappe-react-sdk

React hooks for Frappe
https://frappe-react.vercel.app
MIT License
107 stars 36 forks source link

Not able to connect socket. #50

Closed santhoshkumarguna closed 6 months ago

santhoshkumarguna commented 9 months ago

i have configured frappe provider for my react application and then my frappe server is running on separate url. now i am getting cors error.

image

below error got from my network.

image

This is my source code. image

Kindly help me to solve this issue.

nikkothari22 commented 9 months ago

Hi @santhoshkumarguna - in your site_config.json allow requests from the frontend URL for CORS. I think the key would be "allow_cors". You would need to mention both URLs in site_config

https://stackoverflow.com/questions/64229353/frappe-framework-erpnext-how-to-enable-cors-on-localhost

santhoshkumarguna commented 9 months ago

Hi @nikkothari22 in my react application the web socket url being like this https://chat-test.fr8.in/socket.io/?EIO=4&transport=polling&t=OmKCtiI

when i see the chat on separate site web socket url being like this wss://draven.fr8.in/socket.io/?EIO=4&transport=websocket&sid=SXUvTL-yMs9cHnxGAdTL

I put that you provided code still i getting cors error.

In frappe socket configuration code blocks like this image

nikkothari22 commented 9 months ago

Hey @santhoshkumarguna

Did you add the URL to your allow CORS list in your site_config.json? Can you share that?

This error is not related to the SDK or the frontend. It's the server that's not accepting the request because it's cross origin.

santhoshkumarguna commented 9 months ago

This is my site_config.json file

{ "db_name": "_d1202f0547830600", "db_password": "Wr0BQWKvbpg0kQj9", "db_type": "mariadb", "encryption_key": "maZ4BxtH0RIbOzekEVZ0PG49B5x-l1PeFQzPnJkFwww=", "maintenance_mode": 0, "throttle_user_limit": 500, "allow_cors": "https://dgrow.fr8.in" }

I allowed my origin. now cors error has gone but my websocket is not subscribing. not able to listen realtime updates.

nikkothari22 commented 9 months ago

Unrelated to this but you should have two URL's in your allow_cors - one is your frontend the other is your main frappe server.

This seems like a CORS issue for socket.io in Frappe, rather than an issue with Frappe React SDK. You would have to debug if you can connect to socket directly from a separate origin (without the SDK) - I think that won't work, maybe because Frappe does not check for the allow CORS flag for Socket. (Similarly, API Key secret auth does not work with Socket on Frappe).

If you're not able to connect using Socket to Frappe from a different origin, then the issue is with the framework and not the SDK.