Skip to content

Commit

Permalink
Cc/serve UI assets (#58)
Browse files Browse the repository at this point in the history
closes #57
  • Loading branch information
ccurme authored Mar 20, 2024
1 parent 6e80282 commit a27077c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions backend/server/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,6 +15,8 @@
extraction_runnable,
)

logger = logging.getLogger(__name__)

app = FastAPI(
title="Extraction Powered by LangChain",
description="An extraction service powered by LangChain.",
Expand All @@ -24,6 +29,8 @@
],
)

ROOT = Path(__file__).parent.parent

ORIGINS = os.environ.get("CORS_ORIGINS", "").split(",")

if ORIGINS:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a27077c

Please sign in to comment.