简体   繁体   English

从 webpack 开发服务器到 flask 后端连接的开发代理被拒绝

[英]Dev Proxy from webpack dev server to flask backend connection refused

I've been working on a react app and I wanted to get hot re-loading going so I set up a webpack dev server.我一直在开发一个 React 应用程序,我想进行热重新加载,所以我设置了一个 webpack 开发服务器。 It's working great.它工作得很好。 It runs on localhost:8080 and the hot re-loading works perfectly.它在 localhost:8080 上运行,热重载完美运行。

Great, now I just need to set up a proxy to route requests from 8080 to my flask server running on 5000 right?太好了,现在我只需要设置一个代理来将请求从 8080 路由到运行在 5000 上的 flask 服务器,对吗?

Cool so I added a proxy field to my webpack.config.js很酷,所以我在 webpack.config.js 中添加了一个代理字段

 27     devServer: { 
 28         static: './static/dist',
 29         proxy: {
 30             '/': 'http://localhost:5000',
 31             secure:false,
 32         }
 33     },

But when I re-run npm run start但是当我重新运行 npm run start

  "start": "webpack serve --open --mode=development"

I get all of these connection refused errors.我收到所有这些连接被拒绝的错误。 My flask is up and running fine and I can query the api routes directly and have data be returned.我的flask已经正常运行了,可以直接查询api路由并返回数据。

[webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/all_users to http://localhost:5000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)   

I followed the URL and the only advice there was that this error usually occurs when the external system is down.我遵循了 URL,唯一的建议是这个错误通常在外部系统关闭时发生。 Since mine isn't, I'm pretty confused.因为我的不是,我很困惑。

Any help would be greatly appreciated.任何帮助将不胜感激。

I have no idea why but changing 'http://localhost:5000' to 'http://127.0.0.1:5000' solved my problem.我不知道为什么,但将 'http://localhost:5000' 更改为 'http://127.0.0.1:5000' 解决了我的问题。

If anyone knows I'd still be curious why this fixed it.如果有人知道我仍然很好奇为什么这会修复它。 I can go to 'http://localhost:5000' in my browser and query my backend just fine.我可以在我的浏览器中输入 go 到 'http://localhost:5000' 并查询我的后端就好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM