Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept endpoints that end with a / #422

Merged
merged 1 commit into from
Dec 28, 2022
Merged
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
19 changes: 11 additions & 8 deletions ecowitt2mqtt/helpers/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ def __init__(self, fastapi: FastAPI, endpoint: str) -> None:
self._endpoint = endpoint
self._payload_received_callbacks: list[CallbackT] = []

fastapi.add_api_route(
self._normalize_endpoint(endpoint),
self._async_handle_query, # type: ignore[arg-type]
methods=[self.HTTP_REQUEST_VERB.lower()],
response_class=Response,
status_code=status.HTTP_204_NO_CONTENT,
)
normalized_endpoint = self._normalize_endpoint(endpoint)

for route in (normalized_endpoint, f"{normalized_endpoint}/"):
fastapi.add_api_route(
route,
self._async_handle_query, # type: ignore[arg-type]
methods=[self.HTTP_REQUEST_VERB.lower()],
response_class=Response,
status_code=status.HTTP_204_NO_CONTENT,
)

async def _async_handle_query(self, request: Request) -> None:
"""Handle an API query.
Expand Down Expand Up @@ -104,7 +107,7 @@ def _normalize_endpoint(self, endpoint: str) -> str:
Returns:
A normalized endpoint.
"""
return self._endpoint + "{param_string}"
return endpoint + "{param_string}"

async def async_parse_request_payload(self, request: Request) -> dict[str, Any]:
"""Parse and return the request payload.
Expand Down