2025-12-20 22:18:14 +01:00
|
|
|
"""FastAPI application entry point."""
|
2025-12-21 21:54:26 +01:00
|
|
|
|
2025-12-18 21:48:41 +01:00
|
|
|
from contextlib import asynccontextmanager
|
2025-12-18 23:33:32 +01:00
|
|
|
|
2025-12-20 22:18:14 +01:00
|
|
|
from fastapi import FastAPI
|
2025-12-18 21:37:28 +01:00
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
2025-12-21 21:54:26 +01:00
|
|
|
from database import Base, engine
|
2025-12-20 22:18:14 +01:00
|
|
|
from routes import audit as audit_routes
|
|
|
|
|
from routes import auth as auth_routes
|
2025-12-20 23:36:11 +01:00
|
|
|
from routes import availability as availability_routes
|
2025-12-22 18:22:46 +01:00
|
|
|
from routes import exchange as exchange_routes
|
2025-12-21 21:54:26 +01:00
|
|
|
from routes import invites as invites_routes
|
|
|
|
|
from routes import meta as meta_routes
|
|
|
|
|
from routes import profile as profile_routes
|
2025-12-20 23:06:05 +01:00
|
|
|
from validate_constants import validate_shared_constants
|
2025-12-18 21:48:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
|
async def lifespan(app: FastAPI):
|
2025-12-20 23:06:05 +01:00
|
|
|
"""Create database tables on startup and validate constants."""
|
|
|
|
|
# Validate shared constants match backend definitions
|
|
|
|
|
validate_shared_constants()
|
2025-12-21 21:54:26 +01:00
|
|
|
|
2025-12-18 21:48:41 +01:00
|
|
|
async with engine.begin() as conn:
|
|
|
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
2025-12-18 21:37:28 +01:00
|
|
|
|
|
|
|
|
app.add_middleware(
|
|
|
|
|
CORSMiddleware,
|
|
|
|
|
allow_origins=["http://localhost:3000"],
|
|
|
|
|
allow_methods=["*"],
|
|
|
|
|
allow_headers=["*"],
|
2025-12-18 22:08:31 +01:00
|
|
|
allow_credentials=True,
|
2025-12-18 21:37:28 +01:00
|
|
|
)
|
|
|
|
|
|
2025-12-22 09:10:26 +01:00
|
|
|
# Include routers - modules with single router
|
2025-12-20 22:18:14 +01:00
|
|
|
app.include_router(auth_routes.router)
|
|
|
|
|
app.include_router(audit_routes.router)
|
|
|
|
|
app.include_router(profile_routes.router)
|
2025-12-20 23:36:11 +01:00
|
|
|
app.include_router(availability_routes.router)
|
2025-12-20 23:06:05 +01:00
|
|
|
app.include_router(meta_routes.router)
|
2025-12-22 09:10:26 +01:00
|
|
|
|
|
|
|
|
# Include routers - modules with multiple routers
|
|
|
|
|
for r in invites_routes.routers:
|
|
|
|
|
app.include_router(r)
|
2025-12-22 18:28:56 +01:00
|
|
|
for r in exchange_routes.routers:
|
|
|
|
|
app.include_router(r)
|