增加外部接口调用开关
This commit is contained in:
12
main.py
12
main.py
@@ -69,12 +69,24 @@ app.include_router(router)
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
# 检查环境,生产环境下禁用根接口
|
||||
if settings.environment == "production":
|
||||
logger.warning("🚫 生产环境下禁止访问根接口")
|
||||
from fastapi import HTTPException
|
||||
raise HTTPException(status_code=404, detail="Not Found")
|
||||
|
||||
logger.info("📝 根接口被访问")
|
||||
return {"message": f"Welcome to {settings.app_name}"}
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
# 检查环境,生产环境下禁用健康检查接口
|
||||
if settings.environment == "production":
|
||||
logger.warning("🚫 生产环境下禁止访问健康检查接口")
|
||||
from fastapi import HTTPException
|
||||
raise HTTPException(status_code=404, detail="Not Found")
|
||||
|
||||
logger.debug("💓 健康检查接口被访问")
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user