39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import settings
|
|
from app.database import engine
|
|
from app.models import Base
|
|
from app.api import programs, events, tiers
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Create tables on startup (seed.py handles data seeding)
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title="KMountain Flower Radio API",
|
|
description="Backend API for the KMountain Flower Radio Station website.",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Register routers
|
|
app.include_router(programs.router, prefix="/api/programs", tags=["programs"])
|
|
app.include_router(events.router, prefix="/api/events", tags=["events"])
|
|
app.include_router(tiers.router, prefix="/api/tiers", tags=["tiers"])
|