I am making a simple API for a blog site that I am making for fun. I have my backend logic setup and it looks good. i was even able to post a couple of entries into my DB but I was never able to successfully execute a GET request to the same route (500 Server Error)…Then I closed down my server (localhost:3000) and started it back up and now I am getting the same error for my POST request which was previously successful. I don’t know what to do, please help.
Here is an example of my error message and below that I will post a my get and post code:
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 0
ETag: W/“0-2jmj7l5rSw0yVb/vlWAYkK/YBwk”
Set-Cookie: connect.sid=s%3Az0uu1YK-Z-4ml90AnvrXNgiQdRCzR6Br.CHM1GQNeu4rd5rp1wfounKaXC6XaAnCPoya%2BaqavkF0; Path=/; HttpOnly
Date: Wed, 21 Feb 2024 16:39:19 GMT
Connection: close
exports.getHome = asyncHandler(async (req, res, next) => {
const { user } = req.user;
try {
const posts = await Post.find({}).exec();
res.json(posts);
} catch (error) {
res.status(500).json({ message: error.message });
}
});```
``
exports.getPost = asyncHandler(async (req, res, next) => {
try {
const post = await Post.findById(req.params.id).populate("comments").exec();
res.json(post);
} catch (error) {
res.status(500).json({ message: error.message });
}
});