首页 > 解决方案 > 如何在 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)
        
    }

}

标签: javascriptnode.jsreactjsfrontendbackend

解决方案


推荐阅读