feat: 登录页后端级别隔离,未登录时服务器不返回主页面源码

This commit is contained in:
2026-04-23 11:56:45 +08:00
parent 224de1bd69
commit a378943ec0
6 changed files with 240 additions and 209 deletions
+10 -5
View File
@@ -168,11 +168,16 @@ async def health_check():
# ==================== 页面路由 ====================
@app.get("/", response_class=HTMLResponse)
async def index():
"""返回主页"""
index_file = STATIC_DIR / "index.html"
if index_file.exists():
return HTMLResponse(content=index_file.read_text(encoding='utf-8'))
async def index(request: Request):
"""根据登录状态返回对应页面"""
token = request.cookies.get("token")
if token and verify_jwt_token(token):
index_file = STATIC_DIR / "index.html"
if index_file.exists():
return HTMLResponse(content=index_file.read_text(encoding='utf-8'))
login_file = STATIC_DIR / "login.html"
if login_file.exists():
return HTMLResponse(content=login_file.read_text(encoding='utf-8'))
return HTMLResponse(content="<h1>CapacityReport</h1><p>Static files not found.</p>")