![](/img/trans.png)
[英]Proxy error: Could not proxy request ... from localhost:3000 to http://localhost:5000/
[英]Proxy error: Could not proxy request /time from localhost:3000 to http://localhost:5000
我正在开发一个简单的React-Flask 应用程序,旨在从后端获取当前时间并将其显示在前端。
我有 Flask 后端和 React 前端同时运行。
后端在port 5000
上运行良好:
即使我在package.json
中定义了我的代理,从前端获取调用'/time'
也无法获取当前时间:
"proxy": "http://localhost:5000"
前端:
function App() {
const [currentTime, setCurrentTime] = useState(0);
const getCurrentTime = async (API) => {
const response = await fetch(API);
const jsonData = await response.json();
setCurrentTime(jsonData.time);
console.log(jsonData);
};
useEffect(() => {
// getCurrentTime('http://localhost:5000/time');
getCurrentTime('/time');
}, []);
我已经尝试过这里讨论的方法。 但他们似乎都不适合我。
“代理”:“http://127.0.0.1:5000”。 这个解决方案对我有用。 我收到此错误的原因是我不知道在 package.json 中进行更改后必须重新启动开发服务器。
这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.