Skip to content

Commit fb7377c

Browse files
authored
New UI: Use URL from window.location (#4281)
1 parent 3792f2d commit fb7377c

9 files changed

Lines changed: 69 additions & 9 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
title: using window.location.origin rather than hard coded URL
2+
type: fixed
3+
authors:
4+
- name: Renato Haeberli
5+
6+
links:
7+
- name: PR#4281
8+
url: https://github.com/apache/solr/pull/4281
9+
10+

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.apache.solr.ui.components.start.store.StartStore.Intent
2323
import org.apache.solr.ui.components.start.store.StartStore.Label
2424
import org.apache.solr.ui.components.start.store.StartStore.State
2525
import org.apache.solr.ui.domain.AuthMethod
26+
import org.apache.solr.ui.utils.defaultSolrUrl
2627

2728
/**
2829
* State store interface of the start screen.

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.apache.solr.ui.components.start.store.StartStore.Intent
3333
import org.apache.solr.ui.components.start.store.StartStore.Label
3434
import org.apache.solr.ui.components.start.store.StartStore.State
3535
import org.apache.solr.ui.errors.UnauthorizedException
36-
import org.apache.solr.ui.utils.DEFAULT_SOLR_URL
36+
import org.apache.solr.ui.utils.defaultSolrUrl
3737
import org.apache.solr.ui.utils.parseError
3838

3939
/**
@@ -83,7 +83,7 @@ internal class StartStoreProvider(
8383
is Intent.UpdateSolrUrl -> dispatch(Message.UrlUpdated(intent.url))
8484
is Intent.Connect -> {
8585
var urlValue = state().url
86-
if (urlValue == "") urlValue = DEFAULT_SOLR_URL // use placeholder value if empty
86+
if (urlValue.isBlank()) urlValue = defaultSolrUrl()
8787

8888
try {
8989
val url = parseUrl(urlValue) ?: throw URLParserException(

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ package org.apache.solr.ui.utils
2121
* The default Solr URL that may be used in various places.
2222
*/
2323
const val DEFAULT_SOLR_URL = "http://127.0.0.1:8983/"
24+
25+
/**
26+
* Returns the default Solr URL for the current platform. On web, this is derived from
27+
* the browser's current origin so the URL is always same-origin and avoids CORS issues.
28+
* On desktop, falls back to [DEFAULT_SOLR_URL].
29+
*/
30+
expect fun defaultSolrUrl(): String

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import org.apache.solr.ui.domain.AuthOption
3636
* URL.
3737
*/
3838
fun getDefaultClient(
39-
url: Url = Url("http://127.0.0.1:8983/"),
39+
url: Url = Url(DEFAULT_SOLR_URL),
4040
block: HttpClientConfig<*>.() -> Unit = {},
4141
) = HttpClient {
4242
defaultRequest {
@@ -74,7 +74,7 @@ fun getHttpClientWithAuthOption(option: AuthOption) = when (option) {
7474
fun getHttpClientWithCredentials(
7575
username: String,
7676
password: String,
77-
url: Url = Url("http://127.0.0.1:8983/"),
77+
url: Url = Url(DEFAULT_SOLR_URL),
7878
realm: String? = null,
7979
) = getDefaultClient(url) {
8080
install(Auth) {
@@ -91,7 +91,7 @@ fun getHttpClientWithCredentials(
9191
fun getHttpClientWithBearerTokens(
9292
accessToken: String,
9393
refreshToken: String? = null,
94-
url: Url = Url("http://127.0.0.1:8983/"),
94+
url: Url = Url(DEFAULT_SOLR_URL),
9595
realm: String? = null,
9696
) = getDefaultClient(url) {
9797
install(Auth) {

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import org.apache.solr.ui.generated.resources.connecting
4444
import org.apache.solr.ui.generated.resources.desc_to_get_started
4545
import org.apache.solr.ui.generated.resources.solr_sun
4646
import org.apache.solr.ui.generated.resources.title_welcome_to_solr
47-
import org.apache.solr.ui.utils.DEFAULT_SOLR_URL
47+
import org.apache.solr.ui.utils.defaultSolrUrl
4848
import org.apache.solr.ui.views.components.SolrButton
4949
import org.apache.solr.ui.views.components.SolrCard
5050
import org.apache.solr.ui.views.components.SolrLinearProgressIndicator
@@ -101,7 +101,7 @@ fun StartContent(
101101
value = model.url,
102102
singleLine = true,
103103
onValueChange = component::onSolrUrlChange,
104-
placeholder = { Text(text = DEFAULT_SOLR_URL) },
104+
placeholder = { Text(text = defaultSolrUrl()) },
105105
enabled = !model.isConnecting,
106106
supportingText = {
107107
model.error?.let {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.solr.ui.utils
19+
20+
actual fun defaultSolrUrl(): String = DEFAULT_SOLR_URL

solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/Main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import kotlinx.coroutines.Dispatchers
3434
import org.apache.solr.ui.components.root.RootComponent
3535
import org.apache.solr.ui.components.root.integration.SimpleRootComponent
3636
import org.apache.solr.ui.utils.DefaultAppComponentContext
37+
import org.apache.solr.ui.utils.defaultSolrUrl
3738
import org.apache.solr.ui.utils.getDefaultClient
3839
import org.apache.solr.ui.views.root.RootContent
3940
import org.apache.solr.ui.views.theme.SolrTheme
@@ -68,8 +69,7 @@ fun main() {
6869
return
6970
}
7071

71-
// TODO Set default request url to values from window location
72-
val httpClient = getDefaultClient()
72+
val httpClient = getDefaultClient(url = Url(defaultSolrUrl()))
7373

7474
val component: RootComponent = SimpleRootComponent(
7575
componentContext = componentContext,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.solr.ui.utils
19+
20+
import kotlinx.browser.window
21+
22+
actual fun defaultSolrUrl(): String = window.location.origin + "/"

0 commit comments

Comments
 (0)