🔧 chore(main.py): refactor setup_app function to add support for backend_only flag

✨ feat(main.py): add backend_only flag to setup_app function to allow running the app without serving static files
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-07 09:44:45 -03:00
commit 76362da42b

View file

@ -70,16 +70,19 @@ def get_static_files_dir():
return frontend_path / "frontend"
def setup_app(static_files_dir: Optional[Path] = None) -> FastAPI:
def setup_app(
static_files_dir: Optional[Path] = None, backend_only: bool = False
) -> FastAPI:
"""Setup the FastAPI app."""
# get the directory of the current file
if not static_files_dir:
static_files_dir = get_static_files_dir()
if not static_files_dir or not static_files_dir.exists():
if not backend_only and (not static_files_dir or not static_files_dir.exists()):
raise RuntimeError(f"Static files directory {static_files_dir} does not exist.")
app = create_app()
setup_static_files(app, static_files_dir)
if not backend_only:
setup_static_files(app, static_files_dir)
return app