diff --git a/README.md b/README.md
index 36ea5a20f..6d995e8c2 100644
--- a/README.md
+++ b/README.md
@@ -13,8 +13,9 @@
+
-
+
diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py
index a3841ec93..377339c98 100644
--- a/src/backend/langflow/__main__.py
+++ b/src/backend/langflow/__main__.py
@@ -1,6 +1,5 @@
import sys
import time
-from fastapi import FastAPI
import httpx
from multiprocess import Process, cpu_count # type: ignore
import platform
@@ -11,9 +10,7 @@ from rich.panel import Panel
from rich import box
from rich import print as rprint
import typer
-from fastapi.staticfiles import StaticFiles
-from fastapi.responses import FileResponse
-from langflow.main import create_app
+from langflow.main import setup_app
from langflow.settings import settings
from langflow.utils.logger import configure, logger
import webbrowser
@@ -144,15 +141,9 @@ def serve(
remove_api_keys=remove_api_keys,
cache=cache,
)
- # get the directory of the current file
- if not path:
- frontend_path = Path(__file__).parent
- static_files_dir = frontend_path / "frontend"
- else:
- static_files_dir = Path(path)
-
- app = create_app()
- setup_static_files(app, static_files_dir)
+ # create path object if path is provided
+ path = Path(path) if path else path
+ app = setup_app(static_files_dir=path)
# check if port is being used
if is_port_in_use(port, host):
port = get_free_port(port)
@@ -200,29 +191,6 @@ def run_on_windows(host, port, log_level, options, app):
run_langflow(host, port, log_level, options, app)
-def setup_static_files(app: FastAPI, static_files_dir: Path):
- """
- Setup the static files directory.
-
- Args:
- app (FastAPI): FastAPI app.
- path (str): Path to the static files directory.
- """
- app.mount(
- "/",
- StaticFiles(directory=static_files_dir, html=True),
- name="static",
- )
-
- @app.exception_handler(404)
- async def custom_404_handler(request, __):
- path = static_files_dir / "index.html"
-
- if not path.exists():
- raise RuntimeError(f"File at path {path} does not exist.")
- return FileResponse(path)
-
-
def is_port_in_use(port, host="localhost"):
"""
Check if a port is in use.
diff --git a/src/backend/langflow/main.py b/src/backend/langflow/main.py
index 2a1293f2e..e937931d6 100644
--- a/src/backend/langflow/main.py
+++ b/src/backend/langflow/main.py
@@ -1,5 +1,9 @@
+from pathlib import Path
+from typing import Optional
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
+from fastapi.responses import FileResponse
+from fastapi.staticfiles import StaticFiles
from langflow.api import router
from langflow.database.base import create_db_and_tables
@@ -33,6 +37,42 @@ def create_app():
return app
+def setup_static_files(app: FastAPI, static_files_dir: Path):
+ """
+ Setup the static files directory.
+ Args:
+ app (FastAPI): FastAPI app.
+ path (str): Path to the static files directory.
+ """
+ app.mount(
+ "/",
+ StaticFiles(directory=static_files_dir, html=True),
+ name="static",
+ )
+
+ @app.exception_handler(404)
+ async def custom_404_handler(request, __):
+ path = static_files_dir / "index.html"
+
+ if not path.exists():
+ raise RuntimeError(f"File at path {path} does not exist.")
+ return FileResponse(path)
+
+
+# app = create_app()
+# setup_static_files(app, static_files_dir)
+def setup_app(static_files_dir: Optional[Path]) -> FastAPI:
+ """Setup the FastAPI app."""
+ # get the directory of the current file
+ if not static_files_dir:
+ frontend_path = Path(__file__).parent
+ static_files_dir = frontend_path / "frontend"
+
+ app = create_app()
+ setup_static_files(app, static_files_dir)
+ return app
+
+
app = create_app()