DEV Community

Discussion on: FullStack setup (Node.js, React.js and MongoDB)

Collapse
 
oscarzapi profile image
oscarzapi

Hi Thiago, Thank you so much for this great tutorial. I followed the whole tutorial exactly as you mentioned and at the end when inserting the post requests to include some products... the console was showing this message:
GET localhost:3000/api/product 404 (Not Found)
dispatchXhrRequest @ xhr.js:178 ........

and then I changed in productService.js, axios.get("/api/product) for axios.get(http://localhost:5000/api/product) and the whole app worked!

I have the proxy in the package.json included and everything...but not sure if I missed something..do you know why this happens?Thank you in advance!!!

Collapse
 
pacheco profile image
Thiago Pacheco

Another thing, you should not include the localhost in your axios.get function call.
It should be axios.get("/api/product", ...).

The base URL definition is already set at the beginning of the application when we build the server and define a port, in this case 5000.

Collapse
 
pacheco profile image
Thiago Pacheco

Hi Oscar,

Are you getting this error in the front-end console or is it in an HTTP client?
If this is in your react app, it seems like something is wrong with the proxy config.

Collapse
 
oscarzapi profile image
oscarzapi

It was showing this error inside Chrome Devtools (where localhost:3000).

Thread Thread
 
pacheco profile image
Thiago Pacheco

Are you able to insert data through an HTTP client like Insomnia or postman?

Thread Thread
 
oscarzapi profile image
oscarzapi

I think I found the issue. I had included the sentence "proxy": "localhost:5000" inside the package.json belonging to the server, and not inside the package.json of the client(react app). May be that one the problem Thiago? Because now I´m not getting any errors.

Thread Thread
 
pacheco profile image
Thiago Pacheco

That was it, for sure Oscar.

Let me know if you have any other questions! :)