1

The Back Story

I am working on an app (source here) that uses flask for a backend api and react w/ react-router (using create-react-app) for the frontend. However, I haven't been able to get the devserver npm start to proxy api requests to flask. After setting FLASK_APP From the project root I run:

flask run -h localhost -p 8000 --debugger

and in another terminal

cd frontend
npm start

The devserver opens a browser window and index.html from react loads. The problem is that every rout that doesn't exist in the react app returns 404 including my backend api endpoints. The 404 message is not the same as the one flask usually returns and no backend requests are logged. I have set "propxy": "http://localhost:8000" in package.json. I am under the impression that this is supposed to proxy missing urls to localhost:8000.

The Question

How do I get the webpack-dev-server to proxy api requests to my backend?

fmoor
  • 349
  • 2
  • 8
  • According to the docs this only proxies requests with `Accept` headers other than `text/html`. Did you try it with `application/json`? Otherwise, this should give full control: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#configuring-the-proxy-manually – sthzg Nov 23 '17 at 22:08
  • I did not have the Accept header. After adding `Accept: application/json` it I now get 404 instead of 200. It still does not seem to hit my backend server though. The 404 message is not the same as what flask returns and there are no requests logged. I will update the question with this new information. – fmoor Nov 24 '17 at 17:05
  • try `flask run -h 0.0.0.0 -p 8000 --debugger` – Elise Chant Mar 19 '18 at 19:21
  • re: `"propxy": "http://localhost:8000"` - not sure if you copied this from your actual package.json, but if you did then you've got an extra "P" that shouldn't be there. – Justin Grant Aug 19 '18 at 05:41

0 Answers0