DEV Community

loading...

Connecting front-end and back-end with react and mongo DB - 404 error

Manuel Alonge
・1 min read

I am trying to connect an app hosted in my localhost:3000 port. The back-end is on the localhost:8080 port (not a remote API but on my own PC. I downloaded a pre-created back-end api and linked the front-end to the back-end with MongoDB using an .env file.

The weird thing is that on MongoDB the connection looks ok, following the tutorial I am using. The backend and the front-end also look alrigh, however, I am unable to login with the form in the screenshot.The error I get when trying to login or create a new user is "xhr.js:178 POST http://localhost:3000/login 404 (Not Found)"

It was a bit hard to put the whole code here, so I am linking you to the front-end repo: https://github.com/manuelalonge/complex-app and the back-end repo: https://github.com/manuelalonge/back-end-api

I can understand the issue is most likely on the back-end but I could not understand where exactly. I tried to get back to the previous lessons in the tutorial but it still doesn't get solved.

Probably it is easier to solve this issue with a screenshare session, so if anybody would contact me I'll be grateful.

Screenshot --> [1]: https://i.stack.imgur.com/jVJzn.png

Discussion (5)

Collapse
calebdeji profile image
calebdeji

Since the backend is hosted on port 8080, the call to the login endpoint should be localhost:8080/login

Collapse
manuelalonge profile image
Manuel Alonge Author

This seems logic, but I am not sure where to edit the port.

Collapse
calebdeji profile image
calebdeji • Edited

What's the content of your .env file? Seems you saved your endpoint URL in your .env file?

Thread Thread
manuelalonge profile image
Manuel Alonge Author

SOLVED! thanks for help. I was wrongly indicating the URL in the main file. Thanks again.

Thread Thread
calebdeji profile image
calebdeji

You are welcome.