35 lines
848 B
Python
35 lines
848 B
Python
import logging
|
||
from flask import Flask
|
||
from .config import Config
|
||
from .extensions import init_extensions, register_namespaces
|
||
from .views import register_blueprints
|
||
|
||
|
||
|
||
def create_app(config_object: type = Config) -> Flask:
|
||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||
app.config.from_object(config_object)
|
||
|
||
# secret_key 从 config 里来
|
||
app.secret_key = app.config["SECRET_KEY"]
|
||
|
||
# logging
|
||
app.logger.setLevel(logging.DEBUG)
|
||
|
||
|
||
register_namespaces(app)
|
||
|
||
# 1) 初始化第三方扩展(db、cache、jwt、cors 等)
|
||
init_extensions(app)
|
||
|
||
|
||
# 2) 注册蓝图(把子文件暴露的蓝图统一挂到 app 上)
|
||
register_blueprints(app)
|
||
|
||
# 3) 其他钩子/命令/错误处理
|
||
@app.route("/healthz")
|
||
def healthz():
|
||
return {"status": "ok"}
|
||
|
||
return app
|