-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (22 loc) · 794 Bytes
/
app.py
File metadata and controls
30 lines (22 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from flask import Flask, send_from_directory, jsonify
# Serve React build output
app = Flask(
__name__,
static_folder=os.path.join("frontend", "dist", "assets"),
static_url_path="/assets",
)
BUILD_DIR = os.path.join(os.path.dirname(__file__), "frontend", "dist")
@app.route("/api/hello")
def hello():
return jsonify({"message": "Hello from Flask!"})
# Catch-all: serve React's index.html for client-side routing
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def serve_react(path):
file_path = os.path.join(BUILD_DIR, path)
if path and os.path.isfile(file_path):
return send_from_directory(BUILD_DIR, path)
return send_from_directory(BUILD_DIR, "index.html")
if __name__ == "__main__":
app.run(debug=True, port=5000)