简体   繁体   中英

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. It's working great. It runs on localhost:8080 and the hot re-loading works perfectly.

Great, now I just need to set up a proxy to route requests from 8080 to my flask server running on 5000 right?

Cool so I added a proxy field to my 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

  "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.

[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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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