This is an automated email from the ASF dual-hosted git repository.

malliaridis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new fb7377cc11c New UI: Use URL from window.location (#4281)
fb7377cc11c is described below

commit fb7377cc11c2cbcd7f7259427699690d9ff15a50
Author: Renato Haeberli <[email protected]>
AuthorDate: Mon Apr 20 22:51:18 2026 +0200

    New UI: Use URL from window.location (#4281)
---
 changelog/unreleased/PR#4281-use-of-current-url-in-new-ui.yml  | 10 ++++++++++
 .../org/apache/solr/ui/components/start/store/StartStore.kt    |  1 +
 .../solr/ui/components/start/store/StartStoreProvider.kt       |  4 ++--
 .../commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt    |  7 +++++++
 .../kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt         |  6 +++---
 .../kotlin/org/apache/solr/ui/views/start/StartContent.kt      |  4 ++--
 .../kotlin/org/apache/solr/ui/utils/PlatformUtils.kt}          |  5 +----
 solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/Main.kt       |  4 ++--
 .../kotlin/org/apache/solr/ui/utils/PlatformUtils.kt}          |  7 +++----
 9 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/changelog/unreleased/PR#4281-use-of-current-url-in-new-ui.yml 
b/changelog/unreleased/PR#4281-use-of-current-url-in-new-ui.yml
new file mode 100644
index 00000000000..b7736d261f8
--- /dev/null
+++ b/changelog/unreleased/PR#4281-use-of-current-url-in-new-ui.yml
@@ -0,0 +1,10 @@
+title: using window.location.origin rather than hard coded URL
+type: fixed
+authors:
+  - name: Renato Haeberli
+
+links:
+  - name: PR#4281
+    url: https://github.com/apache/solr/pull/4281
+
+
diff --git 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.kt
 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.kt
index b1d39632ade..3b1e85fd298 100644
--- 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.kt
+++ 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.kt
@@ -23,6 +23,7 @@ import 
org.apache.solr.ui.components.start.store.StartStore.Intent
 import org.apache.solr.ui.components.start.store.StartStore.Label
 import org.apache.solr.ui.components.start.store.StartStore.State
 import org.apache.solr.ui.domain.AuthMethod
+import org.apache.solr.ui.utils.defaultSolrUrl
 
 /**
  * State store interface of the start screen.
diff --git 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.kt
 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.kt
index 74709cdfa21..f5dea9c7e1c 100644
--- 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.kt
+++ 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.kt
@@ -33,7 +33,7 @@ import 
org.apache.solr.ui.components.start.store.StartStore.Intent
 import org.apache.solr.ui.components.start.store.StartStore.Label
 import org.apache.solr.ui.components.start.store.StartStore.State
 import org.apache.solr.ui.errors.UnauthorizedException
-import org.apache.solr.ui.utils.DEFAULT_SOLR_URL
+import org.apache.solr.ui.utils.defaultSolrUrl
 import org.apache.solr.ui.utils.parseError
 
 /**
@@ -83,7 +83,7 @@ internal class StartStoreProvider(
                 is Intent.UpdateSolrUrl -> 
dispatch(Message.UrlUpdated(intent.url))
                 is Intent.Connect -> {
                     var urlValue = state().url
-                    if (urlValue == "") urlValue = DEFAULT_SOLR_URL // use 
placeholder value if empty
+                    if (urlValue.isBlank()) urlValue = defaultSolrUrl()
 
                     try {
                         val url = parseUrl(urlValue) ?: throw 
URLParserException(
diff --git 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt
index 8b2b9f8f3dc..820ed2498b6 100644
--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt
+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt
@@ -21,3 +21,10 @@ package org.apache.solr.ui.utils
  * The default Solr URL that may be used in various places.
  */
 const val DEFAULT_SOLR_URL = "http://127.0.0.1:8983/";
+
+/**
+ * Returns the default Solr URL for the current platform. On web, this is 
derived from
+ * the browser's current origin so the URL is always same-origin and avoids 
CORS issues.
+ * On desktop, falls back to [DEFAULT_SOLR_URL].
+ */
+expect fun defaultSolrUrl(): String
diff --git 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt
index 928e9e7bdec..7d62408585d 100644
--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt
+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt
@@ -36,7 +36,7 @@ import org.apache.solr.ui.domain.AuthOption
  * URL.
  */
 fun getDefaultClient(
-    url: Url = Url("http://127.0.0.1:8983/";),
+    url: Url = Url(DEFAULT_SOLR_URL),
     block: HttpClientConfig<*>.() -> Unit = {},
 ) = HttpClient {
     defaultRequest {
@@ -74,7 +74,7 @@ fun getHttpClientWithAuthOption(option: AuthOption) = when 
(option) {
 fun getHttpClientWithCredentials(
     username: String,
     password: String,
-    url: Url = Url("http://127.0.0.1:8983/";),
+    url: Url = Url(DEFAULT_SOLR_URL),
     realm: String? = null,
 ) = getDefaultClient(url) {
     install(Auth) {
@@ -91,7 +91,7 @@ fun getHttpClientWithCredentials(
 fun getHttpClientWithBearerTokens(
     accessToken: String,
     refreshToken: String? = null,
-    url: Url = Url("http://127.0.0.1:8983/";),
+    url: Url = Url(DEFAULT_SOLR_URL),
     realm: String? = null,
 ) = getDefaultClient(url) {
     install(Auth) {
diff --git 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.kt 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.kt
index ad08effaa21..8c593171a43 100644
--- 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.kt
+++ 
b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.kt
@@ -44,7 +44,7 @@ import org.apache.solr.ui.generated.resources.connecting
 import org.apache.solr.ui.generated.resources.desc_to_get_started
 import org.apache.solr.ui.generated.resources.solr_sun
 import org.apache.solr.ui.generated.resources.title_welcome_to_solr
-import org.apache.solr.ui.utils.DEFAULT_SOLR_URL
+import org.apache.solr.ui.utils.defaultSolrUrl
 import org.apache.solr.ui.views.components.SolrButton
 import org.apache.solr.ui.views.components.SolrCard
 import org.apache.solr.ui.views.components.SolrLinearProgressIndicator
@@ -101,7 +101,7 @@ fun StartContent(
                 value = model.url,
                 singleLine = true,
                 onValueChange = component::onSolrUrlChange,
-                placeholder = { Text(text = DEFAULT_SOLR_URL) },
+                placeholder = { Text(text = defaultSolrUrl()) },
                 enabled = !model.isConnecting,
                 supportingText = {
                     model.error?.let {
diff --git 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt 
b/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/utils/PlatformUtils.kt
similarity index 87%
copy from solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt
copy to solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/utils/PlatformUtils.kt
index 8b2b9f8f3dc..903512f61e8 100644
--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt
+++ b/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/utils/PlatformUtils.kt
@@ -17,7 +17,4 @@
 
 package org.apache.solr.ui.utils
 
-/**
- * The default Solr URL that may be used in various places.
- */
-const val DEFAULT_SOLR_URL = "http://127.0.0.1:8983/";
+actual fun defaultSolrUrl(): String = DEFAULT_SOLR_URL
diff --git a/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/Main.kt 
b/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/Main.kt
index a224111b4e6..dd6a54f4eb3 100644
--- a/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/Main.kt
+++ b/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/Main.kt
@@ -34,6 +34,7 @@ import kotlinx.coroutines.Dispatchers
 import org.apache.solr.ui.components.root.RootComponent
 import org.apache.solr.ui.components.root.integration.SimpleRootComponent
 import org.apache.solr.ui.utils.DefaultAppComponentContext
+import org.apache.solr.ui.utils.defaultSolrUrl
 import org.apache.solr.ui.utils.getDefaultClient
 import org.apache.solr.ui.views.root.RootContent
 import org.apache.solr.ui.views.theme.SolrTheme
@@ -68,8 +69,7 @@ fun main() {
         return
     }
 
-    // TODO Set default request url to values from window location
-    val httpClient = getDefaultClient()
+    val httpClient = getDefaultClient(url = Url(defaultSolrUrl()))
 
     val component: RootComponent = SimpleRootComponent(
         componentContext = componentContext,
diff --git 
a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt 
b/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/utils/PlatformUtils.kt
similarity index 87%
copy from solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt
copy to solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/utils/PlatformUtils.kt
index 8b2b9f8f3dc..6ed853a1a4e 100644
--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt
+++ b/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/utils/PlatformUtils.kt
@@ -17,7 +17,6 @@
 
 package org.apache.solr.ui.utils
 
-/**
- * The default Solr URL that may be used in various places.
- */
-const val DEFAULT_SOLR_URL = "http://127.0.0.1:8983/";
+import kotlinx.browser.window
+
+actual fun defaultSolrUrl(): String = window.location.origin + "/"

Reply via email to