From 1c619a6a09487425f59b054d0d4cbe30d269d0a1 Mon Sep 17 00:00:00 2001 From: Anton Bakker Date: Tue, 21 Nov 2023 13:27:29 +0100 Subject: [PATCH] allow trailing slash settings.base_url --- src/coordinates_transformation_api/main.py | 8 ++++---- src/coordinates_transformation_api/settings.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coordinates_transformation_api/main.py b/src/coordinates_transformation_api/main.py index 9d3a21d..067bbac 100644 --- a/src/coordinates_transformation_api/main.py +++ b/src/coordinates_transformation_api/main.py @@ -161,28 +161,28 @@ async def landingpage(): # type: ignore # noqa: ANN201 self = Link( title="API Landing Page", rel="self", - href=f"{app_settings.base_url}/?f=json", + href=f"{app_settings.base_url.rstrip('/')}/?f=json", type="application/json", ) oas = Link( title="Open API Specification as JSON", rel="service-desc", - href=f"{app_settings.base_url}/openapi?f=json", + href=f"{app_settings.base_url.rstrip('/')}/openapi?f=json", type="application/openapi+json", ) oas_html = Link( title="Open API Specification as HTML", rel="service-desc", - href=f"{app_settings.base_url}/openapi?f=html", + href=f"{app_settings.base_url.rstrip('/')}/openapi?f=html", type="text/html", ) conformance = Link( title="Conformance Declaration as JSON", rel="http://www.opengis.net/def/rel/ogc/1.0/conformance", - href=f"{app_settings.base_url}/conformance", + href=f"{app_settings.base_url.rstrip('/')}/conformance", type="application/json", ) return LandingPage( diff --git a/src/coordinates_transformation_api/settings.py b/src/coordinates_transformation_api/settings.py index e5dca66..616500c 100644 --- a/src/coordinates_transformation_api/settings.py +++ b/src/coordinates_transformation_api/settings.py @@ -75,7 +75,7 @@ class AppSettings(BaseSettings): ) base_url: str = Field( alias="BASE_URL", - default="http://localhost:8000", + default="http://localhost:8000/", description="base url on wich the API is served", pattern=r"^((https?:\/\/)?[\w-]+(\.[\w-]+)*\.?(:\d+)?(\/\S*)?)", # adapted from https://codegolf.stackexchange.com/a/480 )