Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, send_from_directory
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Define a pasta onde está o build do React
|
| 5 |
+
app = Flask(__name__, static_folder='../frontend/dist', static_url_path='/')
|
| 6 |
+
|
| 7 |
+
@app.route('/')
|
| 8 |
+
def serve_index():
|
| 9 |
+
return send_from_directory(app.static_folder, 'index.html')
|
| 10 |
+
|
| 11 |
+
@app.route('/<path:path>')
|
| 12 |
+
def serve_static_file(path):
|
| 13 |
+
file_path = os.path.join(app.static_folder, path)
|
| 14 |
+
if os.path.exists(file_path):
|
| 15 |
+
return send_from_directory(app.static_folder, path)
|
| 16 |
+
else:
|
| 17 |
+
# Fallback para SPA (React Router)
|
| 18 |
+
return send_from_directory(app.static_folder, 'index.html')
|
| 19 |
+
|
| 20 |
+
if __name__ == '__main__':
|
| 21 |
+
app.run(host='0.0.0.0', port=7860)
|