30 lines
796 B
Python
30 lines
796 B
Python
import os
|
|
from fastapi import FastAPI
|
|
from fastapi_sqlalchemy import DBSessionMiddleware
|
|
import logging.config as logging_config
|
|
from config import init_config
|
|
|
|
|
|
def create_app():
|
|
app = FastAPI()
|
|
|
|
@app.on_event("startup")
|
|
def startup_event():
|
|
# 日志配置
|
|
logging_config.fileConfig('conf/log.ini')
|
|
# 初始化配置文件
|
|
mysql_config = init_config()
|
|
# 添加sqlalchemy数据库中间件
|
|
# once the middleware is applied, any route can then access the database session
|
|
# from the global ``db``
|
|
app.add_middleware(DBSessionMiddleware, db_url=mysql_config.SQLALCHEMY_DATABASE_URI)
|
|
|
|
# 在这里添加API route
|
|
from api import test
|
|
app.include_router(test.router)
|
|
return app
|
|
|
|
|
|
fast_api_app = create_app()
|
|
|