From b07fba72e9c6049ab35f37644ad2b15aa68b9b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Thu, 26 Sep 2024 00:57:08 +0200 Subject: [PATCH] add missing message when running in backend_only (#4002) * add missing message when running in backend_only * actually pass loglevel to backend_cmd --- reflex/reflex.py | 4 ++-- reflex/utils/exec.py | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/reflex/reflex.py b/reflex/reflex.py index c90e328e4..07c1dff5b 100644 --- a/reflex/reflex.py +++ b/reflex/reflex.py @@ -247,13 +247,13 @@ def _run( # In prod mode, run the backend on a separate thread. if backend and env == constants.Env.PROD: - commands.append((backend_cmd, backend_host, backend_port)) + commands.append((backend_cmd, backend_host, backend_port, loglevel, frontend)) # Start the frontend and backend. with processes.run_concurrently_context(*commands): # In dev mode, run the backend on the main thread. if backend and env == constants.Env.DEV: - backend_cmd(backend_host, int(backend_port)) + backend_cmd(backend_host, int(backend_port), loglevel, frontend) # The windows uvicorn bug workaround # https://github.com/reflex-dev/reflex/issues/2335 if constants.IS_WINDOWS and exec.frontend_process: diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index 013fa8734..82fb8d9b3 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -60,6 +60,13 @@ def kill(proc_pid: int): process.kill() +def notify_backend(): + """Output a string notifying where the backend is running.""" + console.print( + f"Backend running at: [bold green]http://0.0.0.0:{get_config().backend_port}[/bold green]" + ) + + # run_process_and_launch_url is assumed to be used # only to launch the frontend # If this is not the case, might have to change the logic @@ -103,9 +110,7 @@ def run_process_and_launch_url(run_command: list[str], backend_present=True): f"App running at: [bold green]{url}[/bold green]{' (Frontend-only mode)' if not backend_present else ''}" ) if backend_present: - console.print( - f"Backend running at: [bold green]http://0.0.0.0:{get_config().backend_port}[/bold green]" - ) + notify_backend() first_run = False else: console.print("New packages detected: Updating app...") @@ -203,6 +208,7 @@ def run_backend( host: str, port: int, loglevel: constants.LogLevel = constants.LogLevel.ERROR, + frontend_present: bool = False, ): """Run the backend. @@ -210,11 +216,16 @@ def run_backend( host: The app host port: The app port loglevel: The log level. + frontend_present: Whether the frontend is present. """ web_dir = get_web_dir() # Create a .nocompile file to skip compile for backend. if web_dir.exists(): (web_dir / constants.NOCOMPILE_FILE).touch() + + if not frontend_present: + notify_backend() + # Run the backend in development mode. if should_use_granian(): run_granian_backend(host, port, loglevel) @@ -288,6 +299,7 @@ def run_backend_prod( host: str, port: int, loglevel: constants.LogLevel = constants.LogLevel.ERROR, + frontend_present: bool = False, ): """Run the backend. @@ -295,7 +307,11 @@ def run_backend_prod( host: The app host port: The app port loglevel: The log level. + frontend_present: Whether the frontend is present. """ + if not frontend_present: + notify_backend() + if should_use_granian(): run_granian_backend_prod(host, port, loglevel) else: