dawit45 commited on
Commit
43b61bd
·
verified ·
1 Parent(s): 47618c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,30 +1,32 @@
1
  import os
2
  from flask import Flask, send_from_directory
3
 
 
4
  app = Flask(__name__, static_folder='dist')
5
 
6
- # 1. Health Check Endpoint
7
  @app.route('/health')
8
  def health_check():
 
9
  return {"status": "healthy", "version": "15.0.0"}, 200
10
 
11
- # 2. Production Routing Logic
12
  @app.route('/', defaults={'path': ''})
13
  @app.route('/<path:path>')
14
  def serve(path):
15
- # Ensure the static folder exists
 
 
 
16
  static_path = os.path.join(app.static_folder, path)
17
 
18
  if path != "" and os.path.exists(static_path):
19
  return send_from_directory(app.static_folder, path)
20
  else:
21
- # Check if index.html exists before serving to prevent 500 errors
22
  index_path = os.path.join(app.static_folder, 'index.html')
23
  if os.path.exists(index_path):
24
  return send_from_directory(app.static_folder, 'index.html')
25
  else:
26
- return f"Abyssinia v15 Error: Build artifacts not found in {app.static_folder}", 404
27
 
28
  if __name__ == "__main__":
29
- # Fallback for local testing; Hugging Face will use Gunicorn
30
  app.run(host='0.0.0.0', port=7860)
 
1
  import os
2
  from flask import Flask, send_from_directory
3
 
4
+ # Initialize Flask, pointing it to the Vite output directory
5
  app = Flask(__name__, static_folder='dist')
6
 
 
7
  @app.route('/health')
8
  def health_check():
9
+ """Hugging Face readiness probe endpoint."""
10
  return {"status": "healthy", "version": "15.0.0"}, 200
11
 
 
12
  @app.route('/', defaults={'path': ''})
13
  @app.route('/<path:path>')
14
  def serve(path):
15
+ """
16
+ Serve static files. If a file is not found (e.g., during client-side routing),
17
+ fallback to index.html to allow React Router to handle the view.
18
+ """
19
  static_path = os.path.join(app.static_folder, path)
20
 
21
  if path != "" and os.path.exists(static_path):
22
  return send_from_directory(app.static_folder, path)
23
  else:
 
24
  index_path = os.path.join(app.static_folder, 'index.html')
25
  if os.path.exists(index_path):
26
  return send_from_directory(app.static_folder, 'index.html')
27
  else:
28
+ return f"Abyssinia v15 Error: Build artifacts not found in {app.static_folder}. Check Docker build stage.", 404
29
 
30
  if __name__ == "__main__":
31
+ # Local testing fallback; Hugging Face will invoke via Gunicorn instead
32
  app.run(host='0.0.0.0', port=7860)