- git
- node
- pyenv-virtualenv
- nginx
brew install pyenv-virtualenv
pyenv virtualenv create flaskexample
pyenv activate flaskexample
brew install nginx
cp /usr/local/etc/nginx/nginx.conf ./
Edit it to add reverse proxying to frontend react app and backend flask app.
http {
...
upstream nodeweb {
server localhost:3000;
}
upstream flaskapp {
server localhost:5000;
}
...
server {
...
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
# enable EventSource
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
proxy_pass http://nodeweb$is_args$args;
}
location ~ /u/(?<section>.*) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_set_header Host $host;
proxy_pass http://flaskapp/$section$is_args$args;
}
}
}
Launch nginx with config
nginx -c $(pwd)/nginx.conf
Run Flask dev server:
FLASK_APP=root/app/hello.py flask run
Run react app:
cd greens
yarn start
Visit the nginx server localhost:8080 You will be served the frontend
Load the flask app backend url
Both are from the same host and port origin and to keep frontend fetches in the same-origin browser security policy.
https://facebook.github.io/react/docs/state-and-lifecycle.html
Try changing the python hello.py response to something other than "Hello World!" and hit the button.
yarn add react-router-dom
Then copy/paste an example from the react-router site