app.py 884 B

1234567891011121314151617181920212223242526272829303132333435
  1. """Application factory."""
  2. from flask import Flask
  3. from app.config.setting import config
  4. def register_blueprints(app):
  5. """Register all application blueprints."""
  6. from app.api.v1 import create_blueprint_v1
  7. from app.routes.health import bp as health_bp
  8. # API v1 under /v1
  9. app.register_blueprint(create_blueprint_v1(), url_prefix="/v1")
  10. # Health endpoint at /health
  11. app.register_blueprint(health_bp)
  12. def create_app(env: str = "default"):
  13. """Create and configure the Flask application."""
  14. app = Flask(__name__)
  15. app.config.from_object(config[env])
  16. # optional: initialize logging and other extensions here
  17. try:
  18. from app.utils.logger import setup_logging
  19. setup_logging(app)
  20. except Exception:
  21. # keep app creation robust even if logging setup fails
  22. pass
  23. register_blueprints(app)
  24. return app