diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-21 12:23:25 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-21 12:23:25 +0200 |
commit | 370236be88beccba0b42a2609cd0ca03c08090fe (patch) | |
tree | 3e87be277c5c75a42fa50952018fc120a46f9c40 /sw-ui/src | |
parent | Fix SW client "request" (diff) | |
download | seven-wonders-370236be88beccba0b42a2609cd0ca03c08090fe.tar.gz seven-wonders-370236be88beccba0b42a2609cd0ca03c08090fe.tar.bz2 seven-wonders-370236be88beccba0b42a2609cd0ca03c08090fe.zip |
Connect to correct port based on dev/prod build
Diffstat (limited to 'sw-ui/src')
-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) { |