feat(backend): 添加服务管理脚本并配置应用基础参数

- 更新 .gitignore 忽略后端日志目录和 PID 文件
- 新增 app_name 配置项并替换主程序中硬编码的应用名称
- 为配置模型添加 extra: ignore 以兼容额外环境变量
- 新增完整的后端服务管理脚本 serv.sh,支持常用管理操作
This commit is contained in:
2026-05-22 00:51:48 +08:00
parent ded7ea1228
commit 53128a6f02
4 changed files with 402 additions and 4 deletions

View File

@@ -2,6 +2,8 @@ from pydantic_settings import BaseSettings
class Settings(BaseSettings):
app_name: str = "孕育无忧"
# Path Prefix
api_prefix: str = "/api"
uploads_prefix: str = "/uploads"
@@ -37,7 +39,7 @@ class Settings(BaseSettings):
port: int = 8000
debug: bool = True
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
model_config = {"env_file": ".env", "env_file_encoding": "utf-8", "extra": "ignore"}
settings = Settings()

View File

@@ -28,7 +28,7 @@ logging.basicConfig(
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger("孕育无忧")
logger = logging.getLogger(settings.app_name)
@asynccontextmanager
@@ -42,7 +42,7 @@ async def lifespan(app: FastAPI):
app = FastAPI(
title="孕育无忧 API",
title=f"{settings.app_name} API",
description="孕期健康检查报告解读后端服务",
version="1.0.0",
lifespan=lifespan,
@@ -111,7 +111,7 @@ app.include_router(share.router, prefix=f"{api_prefix}/share", tags=["分享"])
@app.get(f"{api_prefix}/health")
async def health_check():
return {"status": "ok", "service": "孕育无忧 API"}
return {"status": "ok", "service": f"{settings.app_name} API"}
@app.get("/")