Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/fastapi_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _run(
command: str,
app: Union[str, None] = None,
proxy_headers: bool = False,
server_header: bool = False,
) -> None:
with get_rich_toolkit() as toolkit:
server_type = "development" if command == "dev" else "production"
Expand Down Expand Up @@ -168,6 +169,7 @@ def _run(
root_path=root_path,
proxy_headers=proxy_headers,
log_config=get_uvicorn_log_config(),
server_header=server_header,
)


Expand Down Expand Up @@ -216,6 +218,10 @@ def dev(
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info."
),
] = True,
server_header: Annotated[
bool,
typer.Option(help="Enable/Disable Server header."),
] = False,
) -> Any:
"""
Run a [bold]FastAPI[/bold] app in [yellow]development[/yellow] mode. 🧪
Expand Down Expand Up @@ -251,6 +257,7 @@ def dev(
app=app,
command="dev",
proxy_headers=proxy_headers,
server_header=server_header,
)


Expand Down Expand Up @@ -305,6 +312,10 @@ def run(
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info."
),
] = True,
server_header: Annotated[
bool,
typer.Option(help="Enable/Disable Server header."),
] = False,
) -> Any:
"""
Run a [bold]FastAPI[/bold] app in [green]production[/green] mode. 🚀
Expand Down Expand Up @@ -341,6 +352,7 @@ def run(
app=app,
command="run",
proxy_headers=proxy_headers,
server_header=server_header,
)


Expand Down
7 changes: 7 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_dev() -> None:
"root_path": "",
"proxy_headers": True,
"log_config": get_uvicorn_log_config(),
"server_header": False,
}
assert "Using import string: single_file_app:app" in result.output
assert "Starting development server 🚀" in result.output
Expand Down Expand Up @@ -60,6 +61,7 @@ def test_dev_package() -> None:
"root_path": "",
"proxy_headers": True,
"log_config": get_uvicorn_log_config(),
"server_header": False,
}
assert "Using import string: nested_package.package:app" in result.output
assert "Starting development server 🚀" in result.output
Expand Down Expand Up @@ -94,6 +96,7 @@ def test_dev_args() -> None:
"--app",
"api",
"--no-proxy-headers",
"--server-header",
],
)
assert result.exit_code == 0, result.output
Expand All @@ -108,6 +111,7 @@ def test_dev_args() -> None:
"root_path": "/api",
"proxy_headers": False,
"log_config": get_uvicorn_log_config(),
"server_header": True,
}
assert "Using import string: single_file_app:api" in result.output
assert "Starting development server 🚀" in result.output
Expand Down Expand Up @@ -135,6 +139,7 @@ def test_run() -> None:
"root_path": "",
"proxy_headers": True,
"log_config": get_uvicorn_log_config(),
"server_header": False,
}
assert "Using import string: single_file_app:app" in result.output
assert "Starting production server 🚀" in result.output
Expand Down Expand Up @@ -166,6 +171,7 @@ def test_run_args() -> None:
"--app",
"api",
"--no-proxy-headers",
"--server-header",
],
)
assert result.exit_code == 0, result.output
Expand All @@ -180,6 +186,7 @@ def test_run_args() -> None:
"root_path": "/api",
"proxy_headers": False,
"log_config": get_uvicorn_log_config(),
"server_header": True,
}

assert "Using import string: single_file_app:api" in result.output
Expand Down
Loading