Open urbutisj opened 2 years ago
Hi There, I was following the same project tutorial by Lamadev, and encountered the same issue you mentioned above. Did you find the solution to this issue? If so, please help!
This is probably because of a small addition that was not mentioned in the tutorial.
import the User model in posts.js since we are using it in the get timeline function
const User = require("../models/User");
I have ran into two errors around the timestamp of 23:00.
Error 1 xhr.js:177 GET http://localhost:3000/posts/timeline/608f0498b0e4571414a04042 500 (Internal Server Error) I did research and found that this is an error on the server side of the application that relates. I looked at my posts request and this is what I have (copied it from your github to make sure)
router.get("/timeline/:userId", async (req, res) => { try { const currentUser = await User.findById(req.params.userId); const userPosts = await Post.find({ userId: currentUser._id }); const friendPosts = await Promise.all( currentUser.followings.map((friendId) => { return Post.find({ userId: friendId }); }) ); res.status(200).json(userPosts.concat(...friendPosts)) } catch (err) { res.status(500).json(err); console.log(err) } });
Error 2 Uncaught (in promise) Error: Request failed with status code 500. I have a feeling once I get this situated, that should work as well. Any help would be greatly appreciated.