mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
1、后端优化多环境动态管理:python3 main.py run --env=dev(dev、test、prod,可以不加--env,默认dev)
2、前端加入切换主题功能(布局页面头部背景未生效,待优化)
This commit is contained in:
@@ -39,27 +39,25 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[Any, Any]:
|
||||
"""
|
||||
自定义生命周期
|
||||
"""
|
||||
logger.info(f'{settings.TITLE} 服务开始启动...')
|
||||
await import_modules_async(modules=settings.EVENTS, desc="全局事件", app=app, status=True)
|
||||
logger.info(settings.BANNER + '\n' + f'{settings.TITLE} 服务开始启动...')
|
||||
await import_modules_async(modules=settings.get_events, desc="全局事件", app=app, status=True)
|
||||
logger.info(f'{settings.TITLE} 服务成功启动...')
|
||||
|
||||
yield
|
||||
|
||||
await import_modules_async(modules=settings.EVENTS, desc="全局事件", app=app, status=False)
|
||||
await import_modules_async(modules=settings.get_events, desc="全局事件", app=app, status=False)
|
||||
logger.info(f'{settings.TITLE} 服务关闭...')
|
||||
|
||||
|
||||
def register_middlewares(app: FastAPI) -> None:
|
||||
"""
|
||||
注册中间件
|
||||
"""
|
||||
for middleware in settings.MIDDLEWARES[::-1]:
|
||||
for middleware in settings.get_middlewares[::-1]:
|
||||
if not middleware:
|
||||
continue
|
||||
middleware = import_module(middleware, desc="中间件")
|
||||
app.add_middleware(middleware)
|
||||
|
||||
|
||||
def register_exceptions(app: FastAPI) -> None:
|
||||
"""
|
||||
异常捕捉
|
||||
@@ -73,7 +71,6 @@ def register_exceptions(app: FastAPI) -> None:
|
||||
app.add_exception_handler(FieldValidationError,FieldValidationExceptionHandler)
|
||||
app.add_exception_handler(ResponseValidationError,ResponseValidationHandle)
|
||||
|
||||
|
||||
def register_routers(app: FastAPI) -> None:
|
||||
"""
|
||||
注册根路由
|
||||
@@ -82,7 +79,6 @@ def register_routers(app: FastAPI) -> None:
|
||||
app.include_router(router=MonitorApiRouter)
|
||||
app.include_router(router=CommonApiRouter)
|
||||
|
||||
|
||||
def register_files(app: FastAPI) -> None:
|
||||
"""
|
||||
注册文件相关配置
|
||||
@@ -93,11 +89,11 @@ def register_files(app: FastAPI) -> None:
|
||||
settings.STATIC_ROOT.mkdir(parents=True, exist_ok=True)
|
||||
app.mount(path=settings.STATIC_URL, app=StaticFiles(directory=settings.STATIC_ROOT), name=settings.STATIC_DIR)
|
||||
# 挂载模版文件目录
|
||||
if settings.TEMPLATES_ENABLE:
|
||||
if settings.PROFILES_ENABLE:
|
||||
# 确保日志目录存在
|
||||
settings.TEMPLATES_ROOT.mkdir(parents=True, exist_ok=True)
|
||||
app.mount(path=settings.TEMPLATES_URL, app=StaticFiles(directory=settings.TEMPLATES_ROOT), name=settings.TEMPLATES_DIR)
|
||||
|
||||
settings.PROFILES_ROOT.mkdir(parents=True, exist_ok=True)
|
||||
app.mount(path=settings.PROFILES_URL, app=StaticFiles(directory=settings.PROFILES_ROOT), name=settings.PROFILES_DIR)
|
||||
|
||||
def reset_api_docs(app: FastAPI) -> None:
|
||||
"""
|
||||
自定义配置接口本地静态文档
|
||||
|
||||
Reference in New Issue
Block a user