|
@@ -1,5 +1,6 @@
|
|
|
"""Flask application factory for Work Statistics System."""
|
|
"""Flask application factory for Work Statistics System."""
|
|
|
-from flask import Flask
|
|
|
|
|
|
|
+import os
|
|
|
|
|
+from flask import Flask, send_from_directory
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
from flask_cors import CORS
|
|
from flask_cors import CORS
|
|
|
|
|
|
|
@@ -15,7 +16,12 @@ def create_app(config_name='default'):
|
|
|
Returns:
|
|
Returns:
|
|
|
Configured Flask application instance
|
|
Configured Flask application instance
|
|
|
"""
|
|
"""
|
|
|
- app = Flask(__name__)
|
|
|
|
|
|
|
+ # Check if static folder exists (for production with frontend build)
|
|
|
|
|
+ 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__)
|
|
|
|
|
|
|
|
# Load configuration
|
|
# Load configuration
|
|
|
from app.config import config
|
|
from app.config import config
|
|
@@ -29,6 +35,17 @@ def create_app(config_name='default'):
|
|
|
from app.routes import register_routes
|
|
from app.routes import register_routes
|
|
|
register_routes(app)
|
|
register_routes(app)
|
|
|
|
|
|
|
|
|
|
+ # Serve frontend for non-API routes (SPA support)
|
|
|
|
|
+ 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.errorhandler(404)
|
|
|
|
|
+ def not_found(e):
|
|
|
|
|
+ # Return index.html for SPA client-side routing
|
|
|
|
|
+ return send_from_directory(app.static_folder, 'index.html')
|
|
|
|
|
+
|
|
|
# Create database tables and initialize default admin
|
|
# Create database tables and initialize default admin
|
|
|
with app.app_context():
|
|
with app.app_context():
|
|
|
db.create_all()
|
|
db.create_all()
|