title: Running NPM Build from Flask
body: <p>I have a React front end that I would like to serve on the same origin as my python backend API. I'm trying to use Flask for this, but I'm running into an issue with Flask not finding my static files.</p>
  
  <p>My front end build is generated with <code>npm run build</code> in <code>saas_frontend</code></p>
  
  <p>Here is what my file structure looks like:</p>
  
  <pre><code>    ├── main.py
      ├── requirements.txt
      ├── run.sh
      ├── saas_backend
      ├── saas_frontend
  </code></pre>
  
  <p>Flask is running from <code>main.py</code> and serving my front end in <code>saas_frontend/build</code>:</p>
  
  <pre><code>├── asset-manifest.json
  ├── favicon.ico
  ├── index.html
  ├── manifest.json
  ├── service-worker.js
  └── static
      ├── css
      │   ├── main.096c9e23.css
      │   └── main.096c9e23.css.map
      ├── js
      │   ├── main.8949f17a.js
      │   └── main.8949f17a.js.map
      └── media
          ├── delta.56f5d855.csv
          └── logo.e233ff84.png
  </code></pre>
  
  <p>I declared the new template path and static path in <code>main.py</code> as follows:</p>
  
  <pre class="lang-py prettyprint-override"><code>import os
  from flask import Flask, render_template
  
  template_dir = os.path.abspath('saas_frontend/build/')
  static_dir   = os.path.abspath('saas_frontend/build/static')
  app = Flask(__name__, static_path=static_dir, template_folder=template_dir)
  
  
  @app.route('/')
  def index():
      print template_dir
      print static_dir                                                                                                                                                                                    
      return render_template('index.html')
  </code></pre>
  
  <p>But Flask is still unable to serve my static files and I get this as the output....</p>
  
  <pre><code>127.0.0.1 - - [21/Jul/2017 12:13:14] "GET / HTTP/1.1" 200 -
  127.0.0.1 - - [21/Jul/2017 12:13:14] "GET /static/css/main.096c9e23.css HTTP/1.1" 404 -
  127.0.0.1 - - [21/Jul/2017 12:13:14] "GET /static/js/main.8949f17a.js HTTP/1.1" 404 -
  127.0.0.1 - - [21/Jul/2017 12:13:14] "GET /static/css/main.096c9e23.css HTTP/1.1" 404 -
  127.0.0.1 - - [21/Jul/2017 12:13:14] "GET /static/js/main.8949f17a.js HTTP/1.1" 404 -
  </code></pre>
  
  <p>Is there anything I should be doing differently? How can Flask resolve the right file with path in the error message but be completely unable to serve it to the browser?</p>
  
  <p>Thanks!!</p>