mirror of
https://github.com/logos-blockchain/logos-blockchain-block-explorer-template.git
synced 2026-01-02 13:13:10 +00:00
Add general solutions for URLs.
This commit is contained in:
parent
0fd630d6a4
commit
cafc518860
@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, AsyncIterator, List, Optional
|
from typing import TYPE_CHECKING, AsyncIterator, List, Optional
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin, urlunparse
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
@ -35,8 +35,27 @@ class HttpNodeApi(NodeApi):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def base_url(self):
|
def base_url(self) -> str:
|
||||||
return f"{self.protocol}://{self.host}:{self.port}"
|
if "/" in self.host:
|
||||||
|
host, path = self.host.split("/", 1)
|
||||||
|
path = "/" + path
|
||||||
|
else:
|
||||||
|
host = self.host
|
||||||
|
path = ""
|
||||||
|
|
||||||
|
network_location = f"{host}:{self.port}" if self.port else host
|
||||||
|
|
||||||
|
return urlunparse(
|
||||||
|
(
|
||||||
|
self.protocol,
|
||||||
|
network_location,
|
||||||
|
path,
|
||||||
|
# The following are unused but required
|
||||||
|
"", # Params
|
||||||
|
"", # Query
|
||||||
|
"", # Fragment
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user