Setting up Flask with react-starter-kit

506 Views Asked by At

This questions is pretty specific to the react-starter-kit, though, someone else may be able to help here on the internets. I am trying to use the react-starter-kit with a flask application I am developing. I chose this yeoman generator as it had a lot of things I am looking for, though, I don't want to run on a node server. I have a flask app that I would just like to wire up to the react front end. I can't quite figure out how the node routes know which .js bundled file to include (and Node routes are a bit confounding to me anyways). Where would be the best place to start here?

I think if I could start with a specific question, to what .js file could I have an index.html point to? Or how can I find that?

I am tentative to ask this question here, but I hopefully will be directed to the right place.

Here is my index.html:

<!DOCTYPE html>
<html>
  <head lang="en">
    <meta charset="UTF-8">
    <title>Flask React</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- styles -->
  </head>
  <body>
    <div id="app"></div>
    <!-- scripts -->
    <script type="text/js" src="build/assets.js"></script>
  </body>
</html>

Here is my flask view:

@CORE.route('/', methods=['GET'])
  def index():
      return render_template('index.html')

Here is the build/assets.js

module.exports = {"main":{"js":"/main.js?032d72b634c91d2f8756"}};

Where the /main.js?{{string}} points the that bundled version of the app.

Here is the file directory layout:

App
|-app
  |-Core
    |-view.py
  |-Templates
    |-index.html
|-build
  |-assets.js
|-src
1

There are 1 best solutions below

0
On

What I have decided to do, and what I would recommend doing, is to use Graphene and Flask-GraphQL alongside the react-starter-kit. Then to get to my data I can just have the node server query to the flask server to get the data from postgres. This will allow me to still to data-y things in python with the flask server and produce a RESTful API if needed, but will allow me to benefit from the awesomeness of GraphQL.

I am still getting everything figured out, and I will come back to repost in the future when I get things working all the way.