javascript - 如何在 localhost 上同时运行前端和后端
问题描述
好的,所以我的后端服务器在端口 5050 上运行,而我的前端在端口 3000 上运行,但是当我尝试从后端获取数据时,它给了我一个 manifest.json not found 错误我在 package.json 添加了代理但是仍然没有任何帮助将不胜感激这里是来自 fetch 函数和路由的一些代码
index.js in React
const Book =()=>{
const [books, setBooks] = useState([])
const getBooks = async ()=>{
const response = await fetch("/books");
const books = await response.json();
setBooks(books);
}
back End Logic
const getBooks = async(req,res)=>{
try {
//getting list of all books in Book database
const books = await Book.find();
res.status(200).json(books);
} catch (error) {
res.status(404).send(error.message)
}
}
解决方案
推荐阅读
- vba - 以 .xls 格式导出 Excel 工作簿
- javascript - 从突出显示的句子中的一个单词中删除背景颜色
- class - 继承和指向派生类实例的智能指针
- reactjs - 使用 material-kit-react 部署 gatsbyv2 失败
- python - 对 sklearn 中的 random_state 感到困惑
- python - 在 Sanic 路由参数中指定布尔值
- javascript - 如何对多层深的对象强制执行空检查?
- numpy - 有没有办法将在 C 中创建的 numpy Array 强制转换为 MaskedArray?
- python - 拆分字符串多个分隔符
- c# - 打开 CommonOpenFileDialog 后如何防止窗口样式更改