51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""FastAPI entrypoint for the DMS backend service."""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.router import api_router
|
|
from app.core.config import get_settings
|
|
from app.db.base import init_db
|
|
from app.services.app_settings import ensure_app_settings
|
|
from app.services.handwriting_style import ensure_handwriting_style_collection
|
|
from app.services.storage import ensure_storage
|
|
from app.services.typesense_index import ensure_typesense_collection
|
|
|
|
|
|
settings = get_settings()
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
"""Builds and configures the FastAPI application instance."""
|
|
|
|
app = FastAPI(title="DCM DMS API", version="0.1.0")
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
app.include_router(api_router, prefix="/api/v1")
|
|
|
|
@app.on_event("startup")
|
|
def startup_event() -> None:
|
|
"""Initializes storage directories and database schema on service startup."""
|
|
|
|
ensure_storage()
|
|
ensure_app_settings()
|
|
init_db()
|
|
try:
|
|
ensure_typesense_collection()
|
|
except Exception:
|
|
pass
|
|
try:
|
|
ensure_handwriting_style_collection()
|
|
except Exception:
|
|
pass
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|