diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-18 21:45:01 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-18 21:45:01 +0200 |
commit | 432ce23431a77d76c48ca9abe464efeb4f0885bb (patch) | |
tree | c4d73d074fe6c4f6adbc6c3492f3795356882763 /kvision-modules/kvision-common-remote/src/jsMain/kotlin | |
parent | b625a03f661e9f082b80d827a680acd162ffb080 (diff) | |
download | kvision-432ce23431a77d76c48ca9abe464efeb4f0885bb.tar.gz kvision-432ce23431a77d76c48ca9abe464efeb4f0885bb.tar.bz2 kvision-432ce23431a77d76c48ca9abe464efeb4f0885bb.zip |
Support relative links for remote endpoints
Diffstat (limited to 'kvision-modules/kvision-common-remote/src/jsMain/kotlin')
2 files changed, 11 insertions, 5 deletions
diff --git a/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/CallAgent.kt b/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/CallAgent.kt index 6c1e629c..3d865f04 100644 --- a/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/CallAgent.kt +++ b/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/CallAgent.kt @@ -42,7 +42,7 @@ const val HTTP_UNAUTHORIZED = 401 open class CallAgent { private val kvUrlPrefix = window["kv_remote_url_prefix"] - private val urlPrefix: String = if (kvUrlPrefix != undefined) kvUrlPrefix else "" + private val urlPrefix: String = if (kvUrlPrefix != undefined) "$kvUrlPrefix/" else "" private var counter = 1 /** @@ -66,7 +66,7 @@ open class CallAgent { JSON.plain.stringify(jsonRpcRequest) } return Promise { resolve, reject -> - jQuery.ajax(urlPrefix + url, obj { + jQuery.ajax(urlPrefix + url.drop(1), obj { this.contentType = "application/json" this.data = jsonData this.method = method.name @@ -125,7 +125,7 @@ open class CallAgent { beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null ): Promise<dynamic> { return Promise { resolve, reject -> - jQuery.ajax(urlPrefix + url, obj { + jQuery.ajax(urlPrefix + url.drop(1), obj { this.contentType = if (contentType != "multipart/form-data") contentType else false this.data = data this.method = method.name diff --git a/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt b/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt index 24cea176..8836c7f1 100644 --- a/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt +++ b/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt @@ -33,6 +33,8 @@ import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.builtins.list import kotlinx.serialization.serializer import kotlinx.serialization.stringify +import org.w3c.dom.get +import kotlin.browser.window import kotlin.reflect.KClass /** @@ -456,6 +458,8 @@ open class KVRemoteAgent<T : Any>(val serviceManager: KVServiceMgr<T>) : noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit, noinline handler: suspend (SendChannel<PAR1>, ReceiveChannel<PAR2>) -> Unit ) { + val kvUrlPrefix = window["kv_remote_url_prefix"] + val urlPrefix: String = if (kvUrlPrefix != undefined) "$kvUrlPrefix/" else "" val (url, _) = serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] ?: throw IllegalStateException("Function not specified!") @@ -464,7 +468,7 @@ open class KVRemoteAgent<T : Any>(val serviceManager: KVServiceMgr<T>) : val responseChannel = Channel<PAR2>() try { coroutineScope { - socket.connect(getWebSocketUrl(url)) + socket.connect(getWebSocketUrl(urlPrefix + url.drop(1))) lateinit var responseJob: Job lateinit var handlerJob: Job val requestJob = launch { @@ -532,6 +536,8 @@ open class KVRemoteAgent<T : Any>(val serviceManager: KVServiceMgr<T>) : noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<List<PAR2>>) -> Unit, noinline handler: suspend (SendChannel<PAR1>, ReceiveChannel<List<PAR2>>) -> Unit ) { + val kvUrlPrefix = window["kv_remote_url_prefix"] + val urlPrefix: String = if (kvUrlPrefix != undefined) "$kvUrlPrefix/" else "" val (url, _) = serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] ?: throw IllegalStateException("Function not specified!") @@ -540,7 +546,7 @@ open class KVRemoteAgent<T : Any>(val serviceManager: KVServiceMgr<T>) : val responseChannel = Channel<List<PAR2>>() try { coroutineScope { - socket.connect(getWebSocketUrl(url)) + socket.connect(getWebSocketUrl(urlPrefix + url.drop(1))) lateinit var responseJob: Job lateinit var handlerJob: Job val requestJob = launch { |