|
@@ -83,18 +83,18 @@ async def add_process_time_header(request: Request, call_next):
|
|
|
|
|
|
|
|
|
|
# 动态注册路由
|
|
# 动态注册路由
|
|
-for project_path in os.path.join(CfgBaseInit.project_path, "controller"):
|
|
|
|
- files = [file.split(".")[0] for file in files if file.endswith(".py")]
|
|
|
|
- # 获取每一个文件的 module。
|
|
|
|
- for file in files:
|
|
|
|
- router_module = importlib.import_module(f"controller.{file}")
|
|
|
|
- if hasattr(router_module, "router"):
|
|
|
|
- # 注册路由
|
|
|
|
- app.include_router(
|
|
|
|
- router_module.router,
|
|
|
|
- # dependencies=[Depends(get_token_header)],
|
|
|
|
- responses={404: {"description": "Not found"}},
|
|
|
|
- )
|
|
|
|
|
|
+for file in os.listdir(os.path.join(CfgBaseInit.project_path, "controller")):
|
|
|
|
+ if not file.endswith("py") or '__init__.py' in file:
|
|
|
|
+ continue
|
|
|
|
+ file = file.split('.')[0]
|
|
|
|
+ router_module = importlib.import_module(f"controller.{file}", package=None)
|
|
|
|
+ if hasattr(router_module, "router"):
|
|
|
|
+ # 注册路由
|
|
|
|
+ app.include_router(
|
|
|
|
+ router_module.router,
|
|
|
|
+ # dependencies=[Depends(get_token_header)],
|
|
|
|
+ responses={404: {"description": "Not found"}},
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
|
@app.get("/")
|