diff options
Diffstat (limited to 'sw-ui')
-rw-r--r-- | sw-ui/src/main/kotlin/WebpackUtils.kt | 9 | ||||
-rw-r--r-- | sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/sw-ui/src/main/kotlin/WebpackUtils.kt b/sw-ui/src/main/kotlin/WebpackUtils.kt new file mode 100644 index 00000000..dde1140a --- /dev/null +++ b/sw-ui/src/main/kotlin/WebpackUtils.kt @@ -0,0 +1,9 @@ +package webpack + +external val process: Process + +external interface Process { + val env: dynamic +} + +fun isProdEnv(): Boolean = process.env.NODE_ENV == "production" 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 565cf7ec..36c0848e 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 @@ -14,13 +14,16 @@ import org.luxons.sevenwonders.ui.router.Route import org.luxons.sevenwonders.ui.router.routerSaga import redux.RAction import redux.WrapperAction +import webpack.isProdEnv +import kotlin.browser.window typealias SwSagaContext = SagaContext<SwState, RAction, WrapperAction> @OptIn(ExperimentalCoroutinesApi::class) suspend fun SwSagaContext.rootSaga() = coroutineScope { val action = next<RequestChooseName>() - val session = SevenWondersClient().connect("localhost:8000") + val port = if (isProdEnv()) window.location.port.ifEmpty { "80" } else "8000" + val session = SevenWondersClient().connect("localhost:$port") console.info("Connected to Seven Wonders web socket API") launch(start = CoroutineStart.UNDISPATCHED) { |