diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-24 14:07:18 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-24 14:07:18 +0200 |
commit | e45a95ead2ce5f78ef99b223a44991a112bf1432 (patch) | |
tree | 314834c61ef8b54d317aa9b441ddfab535c8299a /sw-ui/src | |
parent | Keep card visible when used to upgrade wonder (diff) | |
download | seven-wonders-e45a95ead2ce5f78ef99b223a44991a112bf1432.tar.gz seven-wonders-e45a95ead2ce5f78ef99b223a44991a112bf1432.tar.bz2 seven-wonders-e45a95ead2ce5f78ef99b223a44991a112bf1432.zip |
Attempt at fixing mixed content ws call
Diffstat (limited to 'sw-ui/src')
-rw-r--r-- | sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt index 5c426a51..7b56594c 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt @@ -22,8 +22,8 @@ typealias SwSagaContext = SagaContext<SwState, RAction, WrapperAction> @OptIn(ExperimentalCoroutinesApi::class) suspend fun SwSagaContext.rootSaga() = coroutineScope { val action = next<RequestChooseName>() - val serverHost = if (isProdEnv()) window.location.host else "localhost:8000" - val session = SevenWondersClient().connect(serverHost) + val serverUrl = sevenWondersWebSocketUrl() + val session = SevenWondersClient().connect(serverUrl) console.info("Connected to Seven Wonders web socket API") launch(start = CoroutineStart.UNDISPATCHED) { @@ -43,6 +43,15 @@ suspend fun SwSagaContext.rootSaga() = coroutineScope { } } +private fun sevenWondersWebSocketUrl(): String { + if (!isProdEnv()) { + return "ws://localhost:8000" + } + // prevents mixed content requests + val scheme = if (window.location.protocol.startsWith("https")) "wss" else "ws" + return "$scheme://${window.location.host}" +} + private suspend fun serverErrorSaga(session: SevenWondersSession) { session.watchErrors().collect { err -> // TODO use blueprintjs toaster |