Skip to content
11 changes: 10 additions & 1 deletion src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
VENDOR_CONTEXT_HEADER = "tracestate"
AUTHORIZAITON_HEADER = "authorization"
PROPAGATED_HEADERS = {CONTEXT_HEADER, VENDOR_CONTEXT_HEADER, AUTHORIZAITON_HEADER}
DOCS_ENDPOINT = "/docs"


class Tag(str, Enum):
Expand Down Expand Up @@ -132,7 +133,7 @@ async def inner(app: FastAPI):

def get_app(config: ApplicationConfig):
app = FastAPI(
docs_url="/docs",
docs_url=DOCS_ENDPOINT,
title="BlueAPI Control",
summary="BlueAPI wraps bluesky plans and devices and "
"exposes endpoints to send commands/receive data",
Expand Down Expand Up @@ -205,6 +206,14 @@ async def on_token_error_401(_: Request, __: Exception):
)


@secure_router.get("/", include_in_schema=False)
def root_redirect() -> RedirectResponse:
"""Redirect to docs url"""
return RedirectResponse(
status_code=status.HTTP_307_TEMPORARY_REDIRECT, url=DOCS_ENDPOINT
)


@secure_router.get("/environment", tags=[Tag.ENV])
@start_as_current_span(TRACER, "runner")
def get_environment(
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/service/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,16 @@ def test_logout(
)


def test_docs_redirect(
mock_authn_server,
client_with_auth: TestClient,
):
client_with_auth.follow_redirects = False
response = client_with_auth.get("/")
assert response.headers.get("location") == main.DOCS_ENDPOINT
assert response.status_code == status.HTTP_307_TEMPORARY_REDIRECT


@pytest.mark.parametrize("has_oidc_config", [True, False])
def test_logout_when_oidc_config_invalid(
has_oidc_config: bool,
Expand Down