Skip to content

Commit 9da8f09

Browse files
fix: use configured backend_host in notify_backend() instead of hardcoded 0.0.0.0
The notify_backend() function was hardcoding "0.0.0.0" as the backend host in the terminal log output, ignoring the backend_host value set in rxconfig.py or passed via --backend-host CLI argument. This change: - Adds an optional `host` parameter to notify_backend() that falls back to config.backend_host when not provided - Passes the resolved host from run_backend() and run_backend_prod() call sites so CLI --backend-host overrides are reflected in logs - Persists the resolved backend_host in the config (via _set_persistent) so it is available to notify_backend() even when called from the frontend thread in run_process_and_launch_url() Fixes #6165
1 parent 64a0bc6 commit 9da8f09

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

reflex/reflex.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ def _run(
198198
auto_increment=auto_increment_backend,
199199
)
200200

201-
# Apply the new ports to the config.
201+
# Apply the new ports and host to the config.
202202
if frontend_port != config.frontend_port:
203203
config._set_persistent(frontend_port=frontend_port)
204204
if backend_port != config.backend_port:
205205
config._set_persistent(backend_port=backend_port)
206+
if backend_host != config.backend_host:
207+
config._set_persistent(backend_host=backend_host)
206208

207209
# Reload the config to make sure the env vars are persistent.
208210
get_config(reload=True)

reflex/utils/exec.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ def notify_frontend(url: str, backend_present: bool):
157157
)
158158

159159

160-
def notify_backend():
161-
"""Output a string notifying where the backend is running."""
160+
def notify_backend(host: str | None = None):
161+
"""Output a string notifying where the backend is running.
162+
163+
Args:
164+
host: The backend host. If not provided, falls back to the config value.
165+
"""
166+
config = get_config()
167+
effective_host = host or config.backend_host
162168
console.print(
163-
f"Backend running at: [bold green]http://0.0.0.0:{get_config().backend_port}[/bold green]"
169+
f"Backend running at: [bold green]http://{effective_host}:{config.backend_port}[/bold green]"
164170
)
165171

166172

@@ -378,7 +384,7 @@ def run_backend(
378384
(web_dir / constants.NOCOMPILE_FILE).touch()
379385

380386
if not frontend_present:
381-
notify_backend()
387+
notify_backend(host)
382388

383389
# Run the backend in development mode.
384390
if should_use_granian():
@@ -579,7 +585,7 @@ def run_backend_prod(
579585
mount_frontend_compiled_app: Whether to mount the compiled frontend app with the backend.
580586
"""
581587
if not frontend_present:
582-
notify_backend()
588+
notify_backend(host)
583589

584590
environment.REFLEX_MOUNT_FRONTEND_COMPILED_APP.set(mount_frontend_compiled_app)
585591

0 commit comments

Comments
 (0)