|
|
@@ -42,17 +42,21 @@ def create_app(config_name=None):
|
|
|
register_error_handlers(app)
|
|
|
|
|
|
# Serve frontend static files (for Docker deployment)
|
|
|
+ # This must be registered AFTER error handlers to properly catch SPA routes
|
|
|
if app.static_folder and os.path.exists(app.static_folder):
|
|
|
@app.route('/')
|
|
|
def serve_index():
|
|
|
return send_from_directory(app.static_folder, 'index.html')
|
|
|
|
|
|
- @app.route('/<path:path>')
|
|
|
- def serve_static(path):
|
|
|
- # If file exists, serve it; otherwise serve index.html for SPA routing
|
|
|
- file_path = os.path.join(app.static_folder, path)
|
|
|
- if os.path.exists(file_path) and os.path.isfile(file_path):
|
|
|
- return send_from_directory(app.static_folder, path)
|
|
|
+ # Catch-all route for SPA - must be the last route registered
|
|
|
+ @app.errorhandler(404)
|
|
|
+ def serve_spa(error):
|
|
|
+ # Check if this is an API request
|
|
|
+ from flask import request
|
|
|
+ if request.path.startswith('/api/'):
|
|
|
+ # Return JSON error for API requests
|
|
|
+ return {'error': {'code': 'RESOURCE_NOT_FOUND', 'message': 'Resource not found'}}, 404
|
|
|
+ # For non-API requests, serve index.html for SPA routing
|
|
|
return send_from_directory(app.static_folder, 'index.html')
|
|
|
|
|
|
return app
|