mirror of
https://git.victorphan.net/basketballcantho/ten-project.git
synced 2026-08-05 13:53:11 +07:00
29 lines
754 B
Python
29 lines
754 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from .database import Base, engine
|
|
from .routers import 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")
|