I have created a MERN chat-app and am facing a few problems. Everything works fine, locally. The problems only start when I host my project, which are as follows:
I am unable to access the hosted backend from my hosted frontend.
The weird part is that if I am running the frontend locally (and calling the hosted backend), it works fine (except for the socket.io part, which obviously can only be accessed with permission). When I use a proxy, I get a 404 error, and when I don’t, I get a cors error. I also tried installing the cors package, but that again gave a 404 error. Please tell me where am I messing up. Thanks in advance!
Back-end
https://chatter-backend-90rs.onrender.com
https://github.com/DenzilJD/chatter-backend
Front-end
2
Answers
I finally found a working solution. The first thing is that 'proxy' in the package.json of the front-end only works for local environments. So I had to put in the API base link within the fetch requests.
After resolving this issue, I started facing the cors error, which I fixed by installing the cors package, and creating an exception for my front-end. A minor detail that is worth noting is that abc.com and abc.com/ are considered different, which was why my cors error persisted. After I fixed this issue, my app was working as expected!
Edit: Thanks for the help @Jayesh Cholker.
Your signup
API
hitting this URL :Your signup
API
should this URL :