beaucarnes / mern-exercise-tracker-mongodb

MERN exercise tracker - code for tutorial
701 stars 620 forks source link

Not able to re-run the application #32

Open Adi1505-macintosh opened 3 years ago

Adi1505-macintosh commented 3 years ago

After coding the first time, I was able to run the application and connect to database properly. However, after a week when I tried to start the serve (nodemon serve & npm start), I don't see the database connected or any sucessfull port connection. The UI is visible but trying to add users gives this issue:

[Error] Could not connect to the server.
[Error] XMLHttpRequest cannot load http://localhost:5000/users/add due to access control checks.
[Error] Failed to load resource: Could not connect to the server. (add, line 0)
[Error] Unhandled Promise Rejection: Error: Network Error
    (anonymous function) (0.chunk.js:954)
    promiseReactionJob

Same with adding exercise. No users visible. MongoDB shows that the relevant databases and records.

Any idea, what needs to be done while restarting the application on localhost?

krukm commented 3 years ago

Did you start the server in a separate terminal tab? I had this issue too, but having two terminals solved the problem. One runs the server and the other your react page.

Adi1505-macintosh commented 3 years ago

I did it on separate terminal tab but still not running. One is running nodemon server (backend) and the other one is npm start. Anything else one has to add?

krukm commented 3 years ago

Did you add { useUnifiedTopology: true } to server.js mongoose.connect?

mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true }
Adi1505-macintosh commented 3 years ago

Still gives the same error. The backend is connected (port and database). It seems to be a front-end issue.

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (add, line 0)
[Error] Unhandled Promise Rejection: Error: Request failed with status code 404
    (anonymous function) (vendors~main.chunk.js:1330)
    promiseReactionJob
shenbao123 commented 3 years ago

Hi, I'm having the same issue, front uses port :3000 and backend uses port :5000. Running both on different terminals gives me the status 404 error which does not let me fetch data from the server within the react app What seems to be the problem?