title: Serving a front end created with create-react-app with Flask
body: <p>I have a Flask back-end with API routes which are accessed by a React single page application created using create-react-app. When using the create-react-app dev server, my Flask back end works. </p>
  
  <p>I would like to serve the built (using <code>npm run build</code>) static React app from my Flask server. Building the React app leads to the following directory structure:</p>
  
  <pre><code>- build
    - static
      - css
          - style.[crypto].css
          - style.[crypto].css.map
      - js
          - main.[crypto].js
          - main.[crypto].js.map
    - index.html
    - service-worker.js
    - [more meta files]
  </code></pre>
  
  <p>By <code>[crypto]</code>, I mean the randomly generated strings generated at build time. </p>
  
  <p>Having received the <code>index.html</code> file, the browser then makes the following requests:</p>
  
  <pre><code>- GET /static/css/main.[crypto].css
  - GET /static/css/main.[crypto].css
  - GET /service-worker.js
  </code></pre>
  
  <p>How should I serve these files? I came up with this:</p>
  
  <pre><code>from flask import Blueprint, send_from_directory
  
  static = Blueprint('static', __name__)
  
  @static.route('/')
  def serve_static_index():
      return send_from_directory('../client/build/', 'index.html')
  
  @static.route('/static/&lt;path:path&gt;') # serve whatever the client requested in the static folder
  def serve_static(path):
      return send_from_directory('../client/build/static/', path)
  
  @static.route('/service-worker.js')
  def serve_worker():
      return send_from_directory('../client/build/', 'service-worker.js')
  </code></pre>
  
  <p>This way, the static assets are successfully served.</p>
  
  <p>On the other hand, I could incorporate this with the built-in Flask static utilities. But I do not understand how to configure this. </p>
  
  <p>Is my solution robust enough? Is there a way to use built-in Flask features to serve these assets? Is there a better way to use create-react-app?</p>