skip to Main Content

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

https://chatterdjd.netlify.app/

https://github.com/DenzilJD/chatter

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. Your signup API hitting this URL :

    enter image description here

    Your signup API should this URL :
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search