Code: Select all
react_app_bp = Blueprint(
"react_app", __name__, static_folder="static", template_folder="templates"
)
# Serve static assets (JS, CSS)
@react_app_bp.route("/assets/")
def serve_assets(filename):
return send_from_directory(os.path.join(react_app_bp.static_folder, "assets"), filename)
# Serve the React app's entry point
@react_app_bp.route("/", defaults={"path": ""})
@react_app_bp.route("/")
@login_required
def serve_react_app(path):
build_dir = os.path.join(os.path.dirname(__file__), "static")
if path and os.path.exists(os.path.join(build_dir, path)):
return send_from_directory(build_dir, path)
return send_from_directory(build_dir, "index.html")