已经可以顺利运行
This commit is contained in:
@@ -9,6 +9,9 @@ from ..Convention.Runtime.GlobalConfig import *
|
||||
from ..Convention.Runtime.Architecture import Architecture
|
||||
|
||||
config = ProjectConfig()
|
||||
APP_CONFIG = {
|
||||
"docs_url": "/docs",
|
||||
}
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
@@ -34,11 +37,12 @@ async def lifespan(app: FastAPI):
|
||||
config.Log("Info", "关闭应用完成...")
|
||||
# db.close()
|
||||
|
||||
def generate_app(APP_CONFIG: dict) -> FastAPI:
|
||||
def generate_app(kwargs: dict) -> FastAPI:
|
||||
'''
|
||||
生成FastAPI应用
|
||||
'''
|
||||
app = FastAPI(**APP_CONFIG, lifespan=lifespan)
|
||||
kwargs.update(**APP_CONFIG)
|
||||
app = FastAPI(**kwargs, lifespan=lifespan)
|
||||
|
||||
# 添加并发限制中间件
|
||||
app.add_middleware(ConcurrencyLimitMiddleware)
|
||||
@@ -46,7 +50,7 @@ def generate_app(APP_CONFIG: dict) -> FastAPI:
|
||||
# 注册路由
|
||||
app.include_router(callback.router, prefix="/api", tags=["callback"])
|
||||
app.include_router(health.router, tags=["health"])
|
||||
ImportPlugins(app, config.FindItem("plugin_dir", "Plugins/"))
|
||||
ImportPlugins(app, config.FindItem("plugin_dir", "Plugins"))
|
||||
|
||||
# 注册至框架中
|
||||
Architecture.Register(FastAPI, app, lambda: None)
|
||||
@@ -60,9 +64,12 @@ app: FastAPI = generate_app(config.FindItem("app_config", {}))
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""根路径"""
|
||||
app_name = config.FindItem("app_name", "Application")
|
||||
app_version = config.FindItem("app_version", "0.0.0")
|
||||
config.SaveProperties()
|
||||
return JSONResponse({
|
||||
"message": config.FindItem("app_name", "Application"),
|
||||
"version": config.FindItem("app_version", "0.0.0"),
|
||||
"message": app_name,
|
||||
"version": app_version,
|
||||
"status": "running"
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user