代理错误:无法代理请求/从Localhost开始:3000到http:// localhost:5000
我正在研究一个简单的 react-flask应用,旨在从后端获取当前时间并将其显示在前端。
我有烧瓶后端,而前端的反应都同时奔跑。
后端在端口5000
上的工作正常很好:
从前端发出的调用'/time'
也无法获取当前时间,即使我在package.json.json
:
"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');
}, []);
我尝试了讨论的方法。但是他们似乎都不对我有用。
I am working on a simple React-Flask App which aims to fetch the current time from the Back-end and display it on the Front-end.
I have the Flask Back-end and the React Front-end both running together at the same time.
The back-end is working perfectly fine on port 5000
:
Fetch call '/time'
from the front-end is unable to fetch the current time even tho I have my proxy defined in the package.json
:
"proxy": "http://localhost:5000"
Front-end:
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');
}, []);
I have tried the methods discussed here. But none of them seems to work for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“代理”:“http://127.0.0.1:5000”。这个解决方案对我有用。我收到此错误的原因是我不知道在 package.json 中进行更改后必须重新启动开发服务器。
这对我有用
"proxy": "http://127.0.0.1:5000". this solution worked for me. The reason why I was getting this error is that I didn't know that I have to restart the development server after making changes in the package.json.
This worked for me