Created
March 21, 2020 09:11
-
-
Save phraniiac/acd55d559880e9489dc15fb0ad615205 to your computer and use it in GitHub Desktop.
Serve a react app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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