cm-wisdom-cube/backend/app/main.py

53 lines
1.2 KiB
Python
Raw Normal View History

2025-03-14 16:57:26 +08:00
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy.sql.functions import user
from app.routers import developer, project, requirement, chat, auth
from app.core.database import engine, Base
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
app = FastAPI(title="HNMFBackend", version="0.1.0")
# 跨域
origins = [
"http://localhost",
"http://localhost:5173",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(developer.router)
app.include_router(project.router)
app.include_router(requirement.router)
app.include_router(chat.router)
app.include_router(auth.router)
# 创建生命周期处理器
@asynccontextmanager
async def lifespan(app: FastAPI):
# 启动时执行原on_event("startup")
Base.metadata.create_all(bind=engine)
yield
@app.get("/health")
async def health_check():
return {"status", "ok"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)