mirror of
https://git.victorphan.net/basketballcantho/ten-project.git
synced 2026-08-05 17:43:10 +07:00
30 lines
821 B
Python
30 lines
821 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from .database import Base, engine
|
|
from .routers import annotations, auth, pdfs
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Create all tables on startup (use Alembic for migrations in production)
|
|
Base.metadata.create_all(bind=engine)
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="LMS API", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000"], # Next.js dev server
|
|
allow_credentials=True, # required for cookies
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router, prefix="/api")
|
|
app.include_router(pdfs.router, prefix="/api")
|
|
app.include_router(annotations.router, prefix="/api")
|