Fix API URL: only auto-append /api for bare hostnames
Use urllib.parse to check if the URL has a path component. Only append /api when the path is empty (e.g. https://silo.kindred.internal). URLs that already include a path (e.g. http://localhost:8080/api) are left unchanged. Restore localhost placeholder as the default.
This commit is contained in:
@@ -29,9 +29,14 @@ def _get_api_url() -> str:
|
||||
if not url:
|
||||
url = os.environ.get("SILO_API_URL", "http://localhost:8080/api")
|
||||
url = url.rstrip("/")
|
||||
# Auto-append /api if the user provided just the base hostname
|
||||
if url and not url.endswith("/api"):
|
||||
url = url + "/api"
|
||||
# Auto-append /api when the user provides just a bare origin with no path,
|
||||
# e.g. "https://silo.kindred.internal" -> "https://silo.kindred.internal/api"
|
||||
# but leave URLs that already have a path alone,
|
||||
# e.g. "http://localhost:8080/api" stays as-is.
|
||||
if url:
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
if not parsed.path or parsed.path == "/":
|
||||
url = url + "/api"
|
||||
return url
|
||||
|
||||
|
||||
@@ -1852,7 +1857,7 @@ class Silo_Settings:
|
||||
layout.addWidget(url_label)
|
||||
|
||||
url_input = QtGui.QLineEdit()
|
||||
url_input.setPlaceholderText("https://silo.kindred.internal")
|
||||
url_input.setPlaceholderText("http://localhost:8080/api")
|
||||
current_url = param.GetString("ApiUrl", "")
|
||||
if current_url:
|
||||
url_input.setText(current_url)
|
||||
@@ -1863,9 +1868,9 @@ class Silo_Settings:
|
||||
layout.addWidget(url_input)
|
||||
|
||||
url_hint = QtGui.QLabel(
|
||||
"Enter the server hostname (e.g. https://silo.kindred.internal). "
|
||||
"The /api path is appended automatically. "
|
||||
"Leave empty to use SILO_API_URL environment variable."
|
||||
"Full URL with path (e.g. http://localhost:8080/api) or just the "
|
||||
"hostname (e.g. https://silo.kindred.internal) and /api is "
|
||||
"appended automatically. Leave empty for SILO_API_URL env var."
|
||||
)
|
||||
url_hint.setWordWrap(True)
|
||||
url_hint.setStyleSheet("color: #888; font-size: 11px;")
|
||||
|
||||
Reference in New Issue
Block a user