33 lines
627 B
Python
33 lines
627 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from contextlib import asynccontextmanager
|
|
from app.database import init_db, close_db
|
|
from app.routers import auth
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Initialize database connection on startup"""
|
|
await init_db()
|
|
yield
|
|
await close_db()
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.get("/")
|
|
async def index() -> dict[str, str]:
|
|
return {"version": "0.1.0"}
|
|
|
|
|
|
app.include_router(auth.router)
|