Antigravity commited on
Commit
a22a4c3
·
1 Parent(s): bda4d27

Fix global 500 error, favicon route, and ensure LFS tracking for binary files

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -15,11 +15,15 @@ try:
15
  except ImportError:
16
  load_model = None
17
 
 
 
 
 
18
  app = Flask(__name__,
19
- static_folder='frontend/dist',
20
  static_url_path='')
21
  CORS(app) # Enable CORS for React frontend
22
- app.config['UPLOAD_FOLDER'] = 'static/uploads'
23
  os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
24
 
25
  # Dataset paths
@@ -429,6 +433,10 @@ def apriori_route():
429
 
430
 
431
  # ============ SERVE STATIC UPLOADS (for ML file handling) ============ #
 
 
 
 
432
  @app.route('/static/uploads/<path:filename>')
433
  def serve_upload(filename):
434
  return send_from_directory('static/uploads', filename)
@@ -438,17 +446,13 @@ def serve_static_files(filename):
438
  return send_from_directory('static', filename)
439
 
440
  # ============ SERVE REACT APP (catch-all) ============ #
441
- @app.route('/')
442
- def serve_react():
443
- return send_from_directory(app.static_folder, 'index.html')
444
-
445
  @app.route('/<path:path>')
446
- def serve_react_paths(path):
447
- # Try to serve the file from dist, otherwise serve index.html (for React Router)
448
- file_path = os.path.join(app.static_folder, path)
449
- if os.path.isfile(file_path):
450
  return send_from_directory(app.static_folder, path)
451
- return send_from_directory(app.static_folder, 'index.html')
 
452
 
453
 
454
  if __name__ == '__main__':
 
15
  except ImportError:
16
  load_model = None
17
 
18
+ # Use absolute path for robustness
19
+ BASE_DIR = os.path.abspath(os.path.dirname(__file__))
20
+ static_dir = os.path.join(BASE_DIR, 'frontend', 'dist')
21
+
22
  app = Flask(__name__,
23
+ static_folder=static_dir,
24
  static_url_path='')
25
  CORS(app) # Enable CORS for React frontend
26
+ app.config['UPLOAD_FOLDER'] = os.path.join(BASE_DIR, 'static', 'uploads')
27
  os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
28
 
29
  # Dataset paths
 
433
 
434
 
435
  # ============ SERVE STATIC UPLOADS (for ML file handling) ============ #
436
+ @app.route('/favicon.ico')
437
+ def favicon():
438
+ return '', 204
439
+
440
  @app.route('/static/uploads/<path:filename>')
441
  def serve_upload(filename):
442
  return send_from_directory('static/uploads', filename)
 
446
  return send_from_directory('static', filename)
447
 
448
  # ============ SERVE REACT APP (catch-all) ============ #
449
+ @app.route('/', defaults={'path': ''})
 
 
 
450
  @app.route('/<path:path>')
451
+ def serve(path):
452
+ if path != "" and os.path.exists(os.path.join(app.static_folder, path)):
 
 
453
  return send_from_directory(app.static_folder, path)
454
+ else:
455
+ return send_from_directory(app.static_folder, 'index.html')
456
 
457
 
458
  if __name__ == '__main__':