This commit is contained in:
Cristhian Zanforlin Lousa 2023-06-15 21:37:27 -03:00
commit 7a6472f103
3 changed files with 27 additions and 14 deletions

View file

@ -1,5 +1,6 @@
import sys
import time
from fastapi import FastAPI
import httpx
from multiprocess import Process, cpu_count # type: ignore
import platform
@ -145,18 +146,16 @@ def serve(
update_settings(
config, dev=dev, database_url=database_url, remove_api_keys=remove_api_keys
)
app = create_app()
# 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.mount(
"/",
StaticFiles(directory=static_files_dir, html=True),
name="static",
)
app = create_app(static_files_dir)
setup_static_files(app, static_files_dir)
options = {
"bind": f"{host}:{port}",
"workers": get_number_of_workers(workers),
@ -180,6 +179,21 @@ def serve(
webbrowser.open(f"http://{host}:{port}")
def setup_static_files(app: FastAPI, static_files_dir: str):
"""
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",
)
def print_banner(host, port):
# console = Console()

View file

@ -1,11 +1,12 @@
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
from langflow.api import router
from langflow.database.base import create_db_and_tables
def create_app():
def create_app(static_path: str = "static"):
"""Create the FastAPI app and include the router."""
app = FastAPI()
@ -17,6 +18,10 @@ def create_app():
def get_health():
return {"status": "OK"}
@app.exception_handler(404)
async def custom_404_handler(request, __):
return FileResponse(f"{static_path}/index.html")
app.add_middleware(
CORSMiddleware,
allow_origins=origins,

View file

@ -1,10 +1,4 @@
import {
ForwardRefExoticComponent,
ReactElement,
ReactFragment,
ReactNode,
SVGProps,
} from "react";
import { ForwardRefExoticComponent, ReactElement, ReactNode } from "react";
import { NodeDataType } from "../flow/index";
import { typesContextType } from "../typesContext";
export type InputComponentType = {