File tree Expand file tree Collapse file tree
commonMain/kotlin/org/apache/solr/ui
desktopMain/kotlin/org/apache/solr/ui/utils
wasmJsMain/kotlin/org/apache/solr/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import org.apache.solr.ui.components.start.store.StartStore.Intent
2323import org.apache.solr.ui.components.start.store.StartStore.Label
2424import org.apache.solr.ui.components.start.store.StartStore.State
2525import org.apache.solr.ui.domain.AuthMethod
26+ import org.apache.solr.ui.utils.defaultSolrUrl
2627
2728/* *
2829 * State store interface of the start screen.
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ import org.apache.solr.ui.components.start.store.StartStore.Intent
3333import org.apache.solr.ui.components.start.store.StartStore.Label
3434import org.apache.solr.ui.components.start.store.StartStore.State
3535import org.apache.solr.ui.errors.UnauthorizedException
36- import org.apache.solr.ui.utils.DEFAULT_SOLR_URL
36+ import org.apache.solr.ui.utils.defaultSolrUrl
3737import 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 (
Original file line number Diff line number Diff 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 */
2323const 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
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ import org.apache.solr.ui.domain.AuthOption
3636 * URL.
3737 */
3838fun 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) {
7474fun 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(
9191fun 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 ) {
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ import org.apache.solr.ui.generated.resources.connecting
4444import org.apache.solr.ui.generated.resources.desc_to_get_started
4545import org.apache.solr.ui.generated.resources.solr_sun
4646import 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
4848import org.apache.solr.ui.views.components.SolrButton
4949import org.apache.solr.ui.views.components.SolrCard
5050import 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 {
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import kotlinx.coroutines.Dispatchers
3434import org.apache.solr.ui.components.root.RootComponent
3535import org.apache.solr.ui.components.root.integration.SimpleRootComponent
3636import org.apache.solr.ui.utils.DefaultAppComponentContext
37+ import org.apache.solr.ui.utils.defaultSolrUrl
3738import org.apache.solr.ui.utils.getDefaultClient
3839import org.apache.solr.ui.views.root.RootContent
3940import 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,
Original file line number Diff line number Diff line change 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 + " /"
You can’t perform that action at this time.
0 commit comments