🔀 refactor(main.py): extract get_static_files_dir() function to improve code readability and reusability
🔀 refactor(main.py): simplify setup_app() function by using get_static_files_dir() function to get static files directory
This commit is contained in:
parent
82b973de43
commit
ab61890997
1 changed files with 7 additions and 4 deletions
|
|
@ -59,14 +59,17 @@ def setup_static_files(app: FastAPI, static_files_dir: Path):
|
||||||
return FileResponse(path)
|
return FileResponse(path)
|
||||||
|
|
||||||
|
|
||||||
# app = create_app()
|
def get_static_files_dir():
|
||||||
# setup_static_files(app, static_files_dir)
|
"""Get the static files directory relative to Langflow's main.py file."""
|
||||||
|
frontend_path = Path(__file__).parent
|
||||||
|
return frontend_path / "frontend"
|
||||||
|
|
||||||
|
|
||||||
def setup_app(static_files_dir: Optional[Path] = None) -> FastAPI:
|
def setup_app(static_files_dir: Optional[Path] = None) -> FastAPI:
|
||||||
"""Setup the FastAPI app."""
|
"""Setup the FastAPI app."""
|
||||||
# get the directory of the current file
|
# get the directory of the current file
|
||||||
if not static_files_dir:
|
if not static_files_dir:
|
||||||
frontend_path = Path(__file__).parent
|
static_files_dir = get_static_files_dir()
|
||||||
static_files_dir = frontend_path / "frontend"
|
|
||||||
|
|
||||||
app = create_app()
|
app = create_app()
|
||||||
setup_static_files(app, static_files_dir)
|
setup_static_files(app, static_files_dir)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue