41 lines
1 KiB
Python
41 lines
1 KiB
Python
"""BIM Twin Viewer — FastAPI application entry point."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api import health, elements, upload
|
|
from app.models.database import engine, Base
|
|
|
|
# Import all models so Base.metadata knows about them
|
|
from app.models import element # noqa: F401
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Create database tables on startup."""
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title="BIM Twin Viewer API",
|
|
description="REST API for IFC-based 3D building model inspection",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(upload.router, prefix="/api")
|
|
app.include_router(elements.router, prefix="/api")
|
|
|