|
@@ -1,18 +1,35 @@
|
|
|
-"""
|
|
|
|
|
-app -
|
|
|
|
|
-auther: tanlie
|
|
|
|
|
-date: 2026/8/23
|
|
|
|
|
-"""
|
|
|
|
|
|
|
+"""Application factory."""
|
|
|
|
|
+
|
|
|
from flask import Flask
|
|
from flask import Flask
|
|
|
|
|
|
|
|
|
|
+from app.config.setting import config
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def register_blueprints(app):
|
|
def register_blueprints(app):
|
|
|
|
|
+ """Register all application blueprints."""
|
|
|
from app.api.v1 import create_blueprint_v1
|
|
from app.api.v1 import create_blueprint_v1
|
|
|
- app.register_blueprint(create_blueprint_v1(),url_prefix='/v1')
|
|
|
|
|
|
|
+ from app.routes.health import bp as health_bp
|
|
|
|
|
+
|
|
|
|
|
+ # API v1 under /v1
|
|
|
|
|
+ app.register_blueprint(create_blueprint_v1(), url_prefix="/v1")
|
|
|
|
|
+
|
|
|
|
|
+ # Health endpoint at /health
|
|
|
|
|
+ app.register_blueprint(health_bp)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def create_app():
|
|
|
|
|
|
|
+def create_app(env: str = "default"):
|
|
|
|
|
+ """Create and configure the Flask application."""
|
|
|
app = Flask(__name__)
|
|
app = Flask(__name__)
|
|
|
- app.config.from_object('app.config.setting')
|
|
|
|
|
|
|
+ app.config.from_object(config[env])
|
|
|
|
|
+
|
|
|
|
|
+ # optional: initialize logging and other extensions here
|
|
|
|
|
+ try:
|
|
|
|
|
+ from app.utils.logger import setup_logging
|
|
|
|
|
+
|
|
|
|
|
+ setup_logging(app)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ # keep app creation robust even if logging setup fails
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
register_blueprints(app)
|
|
register_blueprints(app)
|
|
|
return app
|
|
return app
|