|
|
@@ -1,5 +1,5 @@
|
|
|
import os
|
|
|
-from flask import Flask
|
|
|
+from flask import Flask, send_from_directory
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
from flask_migrate import Migrate
|
|
|
from flask_cors import CORS
|
|
|
@@ -15,7 +15,13 @@ def create_app(config_name=None):
|
|
|
if config_name is None:
|
|
|
config_name = os.environ.get('FLASK_ENV', 'development')
|
|
|
|
|
|
- app = Flask(__name__)
|
|
|
+ # Check if static folder exists (for Docker deployment)
|
|
|
+ static_folder = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static')
|
|
|
+ if os.path.exists(static_folder):
|
|
|
+ app = Flask(__name__, static_folder=static_folder, static_url_path='')
|
|
|
+ else:
|
|
|
+ app = Flask(__name__)
|
|
|
+
|
|
|
app.config.from_object(config[config_name])
|
|
|
|
|
|
# Initialize extensions
|
|
|
@@ -35,4 +41,18 @@ def create_app(config_name=None):
|
|
|
from app.errors import register_error_handlers
|
|
|
register_error_handlers(app)
|
|
|
|
|
|
+ # Serve frontend static files (for Docker deployment)
|
|
|
+ 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)
|
|
|
+ return send_from_directory(app.static_folder, 'index.html')
|
|
|
+
|
|
|
return app
|