Fix relative URL creation.

This commit is contained in:
Alejandro Cabeza Romero 2025-12-19 13:04:33 +01:00
parent cafc518860
commit 6fa406f83f
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD

View File

@ -20,10 +20,11 @@ logger = logging.getLogger(__name__)
class HttpNodeApi(NodeApi): class HttpNodeApi(NodeApi):
ENDPOINT_INFO = "/cryptarchia/info" # Paths can't have a leading slash since they are relative to the base URL
ENDPOINT_TRANSACTIONS = "/cryptarchia/transactions" ENDPOINT_INFO = "cryptarchia/info"
ENDPOINT_BLOCKS = "/cryptarchia/blocks" ENDPOINT_TRANSACTIONS = "cryptarchia/transactions"
ENDPOINT_BLOCKS_STREAM = "/cryptarchia/blocks/stream" ENDPOINT_BLOCKS = "cryptarchia/blocks"
ENDPOINT_BLOCKS_STREAM = "cryptarchia/blocks/stream"
def __init__(self, settings: "NBESettings"): def __init__(self, settings: "NBESettings"):
self.host: str = settings.node_api_host self.host: str = settings.node_api_host
@ -38,14 +39,16 @@ class HttpNodeApi(NodeApi):
def base_url(self) -> str: def base_url(self) -> str:
if "/" in self.host: if "/" in self.host:
host, path = self.host.split("/", 1) host, path = self.host.split("/", 1)
path = "/" + path path = f"/{path}"
if not path.endswith("/"):
path += "/"
else: else:
host = self.host host = self.host
path = "" path = ""
network_location = f"{host}:{self.port}" if self.port else host network_location = f"{host}:{self.port}" if self.port else host
return urlunparse( url = urlunparse(
( (
self.protocol, self.protocol,
network_location, network_location,
@ -56,6 +59,7 @@ class HttpNodeApi(NodeApi):
"", # Fragment "", # Fragment
) )
) )
return url
async def get_health(self) -> HealthSerializer: async def get_health(self) -> HealthSerializer:
url = urljoin(self.base_url, self.ENDPOINT_INFO) url = urljoin(self.base_url, self.ENDPOINT_INFO)