52 lines
1.0 KiB
Python
52 lines
1.0 KiB
Python
"""FastAPI 入口"""
|
||
|
||
import uvicorn
|
||
from contextlib import asynccontextmanager
|
||
from fastapi import FastAPI
|
||
from fastapi.middleware.cors import CORSMiddleware
|
||
|
||
from .database import init_db
|
||
from .routers import auth, users, accounts, login, proxy
|
||
|
||
|
||
@asynccontextmanager
|
||
async def lifespan(app: FastAPI):
|
||
init_db()
|
||
yield
|
||
|
||
|
||
app = FastAPI(
|
||
title="斗鱼批量登录后台",
|
||
version="1.0.0",
|
||
lifespan=lifespan,
|
||
)
|
||
|
||
# CORS(开发期允许前端 localhost:5173)
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=["http://localhost:5173", "http://localhost:3000"],
|
||
allow_credentials=True,
|
||
allow_methods=["*"],
|
||
allow_headers=["*"],
|
||
)
|
||
|
||
# 注册路由
|
||
app.include_router(auth.router)
|
||
app.include_router(users.router)
|
||
app.include_router(accounts.router)
|
||
app.include_router(login.router)
|
||
app.include_router(proxy.router)
|
||
|
||
|
||
@app.get("/api/health")
|
||
def health():
|
||
return {"status": "ok"}
|
||
|
||
|
||
def run():
|
||
uvicorn.run("web.backend.main:app", host="0.0.0.0", port=8000, reload=True)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
run()
|