From baf899eaeb470316a72f8be6eca10dbde1a62758 Mon Sep 17 00:00:00 2001 From: Jiang Date: Wed, 11 Mar 2026 17:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=8E=AF=E5=A2=83=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BB=A5=E6=8E=A7=E5=88=B6=E6=96=87=E6=A1=A3=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 1 + app/main.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index c80d0c3..58e79c2 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -6,6 +6,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): PROJECT_NAME: str = "TJWater Server" + ENVIRONMENT: str = "local" API_V1_STR: str = "/api/v1" # JWT 配置 diff --git a/app/main.py b/app/main.py index 401ddce..947647c 100644 --- a/app/main.py +++ b/app/main.py @@ -53,13 +53,17 @@ async def lifespan(app: FastAPI): logger.info("Database connections closed") +# 根据环境配置决定是否启用文档 +is_production = settings.ENVIRONMENT.lower() == "production" + app = FastAPI( lifespan=lifespan, title=settings.PROJECT_NAME, description="TJWater Server - 供水管网智能管理系统", version="1.0.0", - docs_url="/docs", - redoc_url="/redoc", + docs_url=None if is_production else "/docs", + redoc_url=None if is_production else "/redoc", + openapi_url=None if is_production else "/openapi.json", )