summaryrefslogtreecommitdiff
path: root/sw-ui
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-21 12:23:25 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-21 12:23:25 +0200
commit370236be88beccba0b42a2609cd0ca03c08090fe (patch)
tree3e87be277c5c75a42fa50952018fc120a46f9c40 /sw-ui
parentFix SW client "request" (diff)
downloadseven-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')
-rw-r--r--sw-ui/src/main/kotlin/WebpackUtils.kt9
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt5
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) {
bgstack15