Skip to content

Commit 2153f5f

Browse files
committed
Remove option, only accept via ENV var
1 parent 8351fcb commit 2153f5f

2 files changed

Lines changed: 3 additions & 67 deletions

File tree

src/fastapi_cli/cli.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
from pathlib import Path
34
from typing import Annotated, Any
45

@@ -300,13 +301,6 @@ def dev(
300301
help="Comma separated list of IP Addresses to trust with proxy headers. The literal '*' means trust everything."
301302
),
302303
] = None,
303-
public_url: Annotated[
304-
str | None,
305-
typer.Option(
306-
help="The public URL where the server is accessible. Used for the URLs printed at startup. Defaults to [blue]http://HOST:PORT[/blue] from [bold]--host[/bold] and [bold]--port[/bold].",
307-
envvar="FASTAPI_PUBLIC_URL",
308-
),
309-
] = None,
310304
) -> Any:
311305
"""
312306
Run a [bold]FastAPI[/bold] app in [yellow]development[/yellow] mode. 🧪
@@ -345,7 +339,7 @@ def dev(
345339
command="dev",
346340
proxy_headers=proxy_headers,
347341
forwarded_allow_ips=forwarded_allow_ips,
348-
public_url=public_url,
342+
public_url=os.getenv("FASTAPI_PUBLIC_URL"),
349343
)
350344

351345

@@ -415,13 +409,6 @@ def run(
415409
help="Comma separated list of IP Addresses to trust with proxy headers. The literal '*' means trust everything."
416410
),
417411
] = None,
418-
public_url: Annotated[
419-
str | None,
420-
typer.Option(
421-
help="The public URL where the server is accessible. Used for the URLs printed at startup. By default, the printed URLs use the configured host and port.",
422-
envvar="FASTAPI_PUBLIC_URL",
423-
),
424-
] = None,
425412
) -> Any:
426413
"""
427414
Run a [bold]FastAPI[/bold] app in [green]production[/green] mode. 🚀
@@ -460,7 +447,7 @@ def run(
460447
command="run",
461448
proxy_headers=proxy_headers,
462449
forwarded_allow_ips=forwarded_allow_ips,
463-
public_url=public_url,
450+
public_url=os.getenv("FASTAPI_PUBLIC_URL"),
464451
)
465452

466453

tests/test_cli.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -392,55 +392,6 @@ def test_run_env_vars_and_args() -> None:
392392
assert "Documentation at http://0.0.0.0:8080/docs" in result.output
393393

394394

395-
@pytest.mark.parametrize("command", ["dev", "run"])
396-
@pytest.mark.parametrize(
397-
"public_url",
398-
[
399-
"https://myapp.example.com",
400-
"https://myapp.example.com/",
401-
"https://myapp.example.com/subpath/",
402-
],
403-
)
404-
def test_public_url(command: str, public_url: str) -> None:
405-
with changing_dir(assets_path):
406-
with patch.object(uvicorn, "run") as mock_run:
407-
result = runner.invoke(
408-
app,
409-
[
410-
command,
411-
"single_file_app.py",
412-
"--host",
413-
"0.0.0.0",
414-
"--public-url",
415-
public_url,
416-
],
417-
)
418-
assert result.exit_code == 0, result.output
419-
assert mock_run.called
420-
assert mock_run.call_args
421-
assert mock_run.call_args.kwargs == {
422-
"app": "single_file_app:app",
423-
"host": "0.0.0.0",
424-
"port": 8000,
425-
"reload": True if command == "dev" else False,
426-
"reload_dirs": None,
427-
"workers": None,
428-
"root_path": "",
429-
"proxy_headers": True,
430-
"forwarded_allow_ips": None,
431-
"log_config": get_uvicorn_log_config(),
432-
}
433-
434-
assert "Using import string: single_file_app:app" in result.output
435-
assert (
436-
f"Starting {'development' if command == 'dev' else 'production'} server 🚀"
437-
in result.output
438-
)
439-
expected_url_base = public_url.rstrip("/")
440-
assert f"Server started at {expected_url_base}" in result.output
441-
assert f"Documentation at {expected_url_base}/docs" in result.output
442-
443-
444395
@pytest.mark.parametrize("command", ["dev", "run"])
445396
@pytest.mark.parametrize(
446397
"public_url",
@@ -515,7 +466,6 @@ def test_dev_help() -> None:
515466
assert "Set reload directories explicitly" in result.output
516467
assert "The root path is used to tell your app" in result.output
517468
assert "The name of the variable that contains the FastAPI app" in result.output
518-
assert "The public URL where the server is accessible" in result.output
519469
assert "Use multiple worker processes." not in result.output
520470

521471

@@ -537,7 +487,6 @@ def test_run_help() -> None:
537487
assert "Enable auto-reload of the server when (code) files change." in result.output
538488
assert "The root path is used to tell your app" in result.output
539489
assert "The name of the variable that contains the FastAPI app" in result.output
540-
assert "The public URL where the server is accessible" in result.output
541490
assert "Use multiple worker processes." in result.output
542491

543492

0 commit comments

Comments
 (0)