首页web入口暴露
This commit is contained in:
parent
7f5dabea83
commit
0b72ed20bc
18
app/main.py
18
app/main.py
|
|
@ -3,8 +3,11 @@ FastAPI 主应用
|
|||
"""
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse
|
||||
from app.config import settings
|
||||
from app.api import router
|
||||
import os
|
||||
|
||||
|
||||
# 创建 FastAPI 应用实例
|
||||
|
|
@ -26,16 +29,17 @@ app.add_middleware(
|
|||
# 注册路由
|
||||
app.include_router(router, prefix="/api/v1", tags=["AI Chat"])
|
||||
|
||||
# 获取 static 目录的绝对路径
|
||||
static_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "static")
|
||||
|
||||
# 挂载静态文件目录
|
||||
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""根路径"""
|
||||
return {
|
||||
"message": f"欢迎使用 {settings.app_name}",
|
||||
"version": settings.app_version,
|
||||
"docs": "/docs",
|
||||
"redoc": "/redoc"
|
||||
}
|
||||
"""根路径 - 返回主页"""
|
||||
return FileResponse(os.path.join(static_dir, "index.html"))
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
|
|
|
|||
Loading…
Reference in New Issue