diff --git a/backend/server/main.py b/backend/server/main.py index b1454f7..a601771 100644 --- a/backend/server/main.py +++ b/backend/server/main.py @@ -1,8 +1,11 @@ """Entry point into the server.""" +import logging import os +from pathlib import Path from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles from langserve import add_routes from server.api import configurables, examples, extract, extractors, shared, suggest @@ -12,6 +15,8 @@ extraction_runnable, ) +logger = logging.getLogger(__name__) + app = FastAPI( title="Extraction Powered by LangChain", description="An extraction service powered by LangChain.", @@ -24,6 +29,8 @@ ], ) +ROOT = Path(__file__).parent.parent + ORIGINS = os.environ.get("CORS_ORIGINS", "").split(",") if ORIGINS: @@ -59,6 +66,15 @@ def ready() -> str: ) +# Serve the frontend +ui_dir = str(ROOT / "ui") + +if os.path.exists(ui_dir): + app.mount("/", StaticFiles(directory=ui_dir, html=True), name="ui") +else: + logger.warning("No UI directory found, serving API only.") + + if __name__ == "__main__": import uvicorn