feat: 完成登录与栅格下载桌面端
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""本机接口。只监听 127.0.0.1。功能路由按目录挂上。"""
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.features.download.router import router as download_router
|
||||
from app.platform.auth import router as auth_router
|
||||
from app.shared.state import state
|
||||
|
||||
ORIGINS = [
|
||||
"http://localhost:1420",
|
||||
"http://127.0.0.1:1420",
|
||||
"tauri://localhost",
|
||||
"http://tauri.localhost",
|
||||
"https://tauri.localhost",
|
||||
]
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_app: FastAPI):
|
||||
yield
|
||||
if state.client is not None:
|
||||
await state.client.aclose()
|
||||
for client, _challenge in state.flows.values():
|
||||
await client.aclose()
|
||||
|
||||
|
||||
app = FastAPI(title="NqiTools", lifespan=lifespan)
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=ORIGINS,
|
||||
allow_credentials=False,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
app.include_router(auth_router)
|
||||
app.include_router(download_router)
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health() -> dict:
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run("app.main:app", host="127.0.0.1", port=8765)
|
||||
Reference in New Issue
Block a user