Skip to content

Instantly share code, notes, and snippets.

@phraniiac
Created March 21, 2020 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phraniiac/acd55d559880e9489dc15fb0ad615205 to your computer and use it in GitHub Desktop.
Save phraniiac/acd55d559880e9489dc15fb0ad615205 to your computer and use it in GitHub Desktop.
Serve a react app.
import os
from flask import Flask, render_template, send_from_directory
app = Flask(__name__, static_folder="/app", template_folder="/app")
# Serve React App
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def serve(path):
print(path)
if path != "" and os.path.exists(app.static_folder + '/' + path):
return send_from_directory(app.static_folder, path)
else:
return send_from_directory(app.static_folder, 'index.html')
@app.route("/")
def hello():
return render_template('index.html')
app.debug=True
app.run(host='0.0.0.0', port=80)
# app.run(port=80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment