我有一个个人投资组合网站,我正在我的投资组合中集成一个博客,我使用 MERN 堆栈制作,我收到错误 “语法错误:控制台中出现意外标记 '<', "”
以下是项目的git仓库的链接useEffect(() => {
const fetchBlogs = async () => {
try {
const url = `${host}/blog/blogs`;
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
"authtoken": localStorage.getItem("token")
},
});
const allblogs = await response.json();
setBlogs(allblogs);
setLoading(false);
extractUniqueTags(allblogs);
} catch (error) {
console.error('Error fetching blogs:', error.message);
setLoading(false);
}
};
fetchBlogs();
// eslint-disable-next-line
}, []);
后台发送router.get('/blogs', async (req, res) => {
try {
const blogPosts = await BlogPost.find();
res.json({blogPosts: blogPosts});
} catch (error) {
res.status(500).send("Some Error occurred");
}
});