Skip to content

Commit 2b44c5e

Browse files
authored
Merge pull request #1187 from major/fix/rspeed-2467-root-path-doubled-prefix
fix: pass root_path to FastAPI constructor instead of uvicorn
2 parents 5495f95 + 50adeaf commit 2b44c5e

3 files changed

Lines changed: 3 additions & 8 deletions

File tree

src/app/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
8484

8585

8686
app = FastAPI(
87+
root_path=configuration.service_configuration.root_path,
8788
title=f"{service_name} service - OpenAPI",
8889
summary=f"{service_name} service API specification.",
8990
description=f"{service_name} service API specification.",

src/runners/uvicorn.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def start_uvicorn(configuration: ServiceConfiguration) -> None:
1616
1717
Parameters:
1818
configuration (ServiceConfiguration): Configuration providing host,
19-
port, workers, `root_path`, and `tls_config` (including `tls_key_path`,
19+
port, workers, and `tls_config` (including `tls_key_path`,
2020
`tls_certificate_path`, and `tls_key_password`). TLS fields may be None
2121
and will be forwarded to uvicorn.run as provided.
2222
"""
@@ -31,7 +31,6 @@ def start_uvicorn(configuration: ServiceConfiguration) -> None:
3131
host=configuration.host,
3232
port=configuration.port,
3333
workers=configuration.workers,
34-
root_path=configuration.root_path,
3534
log_level=log_level,
3635
ssl_keyfile=configuration.tls_config.tls_key_path,
3736
ssl_certfile=configuration.tls_config.tls_certificate_path,

tests/unit/runners/test_uvicorn_runner.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def test_start_uvicorn(mocker: MockerFixture) -> None:
2222
host="localhost",
2323
port=8080,
2424
workers=1,
25-
root_path="",
2625
log_level=20,
2726
ssl_certfile=None,
2827
ssl_keyfile=None,
@@ -46,7 +45,6 @@ def test_start_uvicorn_different_host_port(mocker: MockerFixture) -> None:
4645
host="x.y.com",
4746
port=1234,
4847
workers=10,
49-
root_path="",
5048
log_level=20,
5149
ssl_certfile=None,
5250
ssl_keyfile=None,
@@ -71,7 +69,6 @@ def test_start_uvicorn_empty_tls_configuration(mocker: MockerFixture) -> None:
7169
host="x.y.com",
7270
port=1234,
7371
workers=10,
74-
root_path="",
7572
log_level=20,
7673
ssl_certfile=None,
7774
ssl_keyfile=None,
@@ -100,7 +97,6 @@ def test_start_uvicorn_tls_configuration(mocker: MockerFixture) -> None:
10097
host="x.y.com",
10198
port=1234,
10299
workers=10,
103-
root_path="",
104100
log_level=20,
105101
ssl_certfile=Path("tests/configuration/server.crt"),
106102
ssl_keyfile=Path("tests/configuration/server.key"),
@@ -111,7 +107,7 @@ def test_start_uvicorn_tls_configuration(mocker: MockerFixture) -> None:
111107

112108

113109
def test_start_uvicorn_with_root_path(mocker: MockerFixture) -> None:
114-
"""Test the function to start Uvicorn server with a custom root path."""
110+
"""Test that root_path is not passed to uvicorn (it belongs on the FastAPI constructor)."""
115111
configuration = ServiceConfiguration(
116112
host="localhost", port=8080, workers=1, root_path="/api/lightspeed"
117113
) # pyright: ignore[reportCallIssue]
@@ -124,7 +120,6 @@ def test_start_uvicorn_with_root_path(mocker: MockerFixture) -> None:
124120
host="localhost",
125121
port=8080,
126122
workers=1,
127-
root_path="/api/lightspeed",
128123
log_level=20,
129124
ssl_certfile=None,
130125
ssl_keyfile=None,

0 commit comments

Comments
 (0)