Skip to content

Commit 1a0b1df

Browse files
fix api_base_url generation
1 parent 5927feb commit 1a0b1df

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

services/web/server/src/simcore_service_webserver/utils_aiohttp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from collections.abc import Callable, Iterator
44
from typing import Any, Generic, Literal, TypeAlias, TypeVar
5+
from urllib.parse import urlparse
56

67
from aiohttp import web
78
from aiohttp.web_exceptions import HTTPError, HTTPException
@@ -165,8 +166,7 @@ def iter_origins(request: web.Request) -> Iterator[str]:
165166

166167

167168
def get_api_base_url(request: web.Request) -> str:
168-
api_host = next(iter_origins(request))
169-
api_host = (
170-
f"api.{api_host}" if not is_ip_address(api_host) else api_host # in tests
171-
)
169+
origin = next(iter_origins(request))
170+
hostname = urlparse(origin).hostname or "localhost"
171+
api_host = f"api.{hostname}" if not is_ip_address(hostname) else hostname
172172
return f"{request.url.with_host(api_host).with_port(None).with_path('')}"

0 commit comments

Comments
 (0)