Skip to content

Commit

Permalink
Integrate CRA with Flask
Browse files Browse the repository at this point in the history
- install packages for flask url building and the babel macro
- provide url map to flask-urls macro
- setup proxying from the CRA server to the flask dev server
  • Loading branch information
ThiefMaster committed Jul 8, 2019
1 parent 1717f75 commit 7d36dac
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions flask_cra_example/client/.babel-plugin-macrosrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {execSync} = require('child_process');

const urlMap = JSON.parse(execSync('flask url_map_to_json'));

module.exports = {
flaskURLs: {
urlMap,
},
};
25 changes: 25 additions & 0 deletions flask_cra_example/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions flask_cra_example/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"flask-urls": "^0.1.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"devDependencies": {
"flask-urls.macro": "^0.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
Expand Down
8 changes: 8 additions & 0 deletions flask_cra_example/client/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const proxy = require('http-proxy-middleware');

// we need a custom proxy config since for some reason the "proxy" option in package.json
// forwards even the websocket requests that are meant for the auto reloader...
// https://github.com/facebook/create-react-app/issues/7323
module.exports = app => {
app.use(proxy('/api', {target: process.env.FLASK_URL || 'http://127.0.0.1:5000'}));
};
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
zip_safe=False,
install_requires=[
'Flask',
'flask_url_map_serializer',
'python-dotenv'
],
)

0 comments on commit 7d36dac

Please sign in to comment.