Skip to content

Fix startup URL showing default port instead of configured port - #546

Open
Christian-Sidak wants to merge 2 commits into
remsky:masterfrom
Christian-Sidak:fix/issue-545
Open

Christian-Sidak wants to merge 2 commits into
remsky:masterfrom
Christian-Sidak:fix/issue-545

Conversation

@Christian-Sidak

Copy link
Copy Markdown
Contributor

Summary

  • When uvicorn is launched via CLI with --port N without the PORT environment variable being explicitly set (e.g. using shell default expansion like ${PORT:-3000}), settings.port stays at its default value (8880) while the server actually listens on the CLI-specified port
  • The lifespan startup message used settings.port directly, so the Beta Web Player URL showed the wrong port
  • Add _get_effective_port() in main.py to inspect sys.argv for --port/--port=/-p arguments, falling back to settings.port when none is found; use it in the startup message

Test plan

  • _get_effective_port() returns settings.port when no --port arg is present
  • _get_effective_port() returns the CLI value when --port N is passed
  • _get_effective_port() handles --port=N (equals form)
  • _get_effective_port() handles -p N (short form)
  • _get_effective_port() falls back gracefully when --port value is non-integer

Fixes #545

When uvicorn is launched via CLI with --port N without also exporting the
PORT environment variable (e.g. using shell default syntax like
${PORT:-3000}), settings.port stays at its default value of 8880 while
the server actually listens on the CLI-specified port. The startup
message then displays the wrong port in the Beta Web Player URL.

Add _get_effective_port(), which inspects sys.argv for --port/--port=/
-p arguments and falls back to settings.port when none is present.
Use it in the lifespan startup message instead of settings.port directly.

Fixes remsky#545

Signed-off-by: Christian Sidak <christian@sentineltech.eu>
Signed-off-by: Christian-Sidak <61099993+Christian-Sidak@users.noreply.github.com>
@remsky

remsky commented Oct 13, 2026

Copy link
Copy Markdown
Owner

thanks for catching this!

Could we hook uvicorn's "running on" log record instead and print the /web/ link from its args? sys.argv may be a bit fragile here (uvicorn has no -p and I think it misses --host, etc).

@Christian-Sidak

Copy link
Copy Markdown
Contributor Author

Good point on sys.argv fragility. Pushed 87e1220: replaced the sys.argv walk with a logging.Handler on uvicorn.error that intercepts the 'running on' record and extracts the port from the bound URL. The lifespan message now just says 'Web Player: enabled (URL logged below)' and the actual link fires when uvicorn logs the socket it opened. This way the displayed port always matches what uvicorn actually bound to, regardless of how it was launched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup URL displays the default port instead of the configured port

2 participants