From f61a115e32c44d010cae16b527a1bb2f22c3b8b5 Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Wed, 11 Dec 2019 20:59:15 +0100 Subject: [PATCH] okay so this should work again, but it's a lot more cursed now (Main.Kt#249) --- src/main/kotlin/nl/voidcorp/sqa/Main.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/nl/voidcorp/sqa/Main.kt b/src/main/kotlin/nl/voidcorp/sqa/Main.kt index d516aa1..f6ac92c 100644 --- a/src/main/kotlin/nl/voidcorp/sqa/Main.kt +++ b/src/main/kotlin/nl/voidcorp/sqa/Main.kt @@ -12,9 +12,7 @@ import io.ktor.features.CallLogging import io.ktor.features.ContentNegotiation import io.ktor.html.respondHtml import io.ktor.http.ContentType -import io.ktor.http.URLProtocol import io.ktor.http.cio.websocket.* -import io.ktor.http.isSecure import io.ktor.jackson.jackson import io.ktor.response.respondRedirect import io.ktor.response.respondText @@ -22,7 +20,6 @@ import io.ktor.routing.get import io.ktor.routing.routing import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty -import io.ktor.util.url import io.ktor.websocket.DefaultWebSocketServerSession import io.ktor.websocket.WebSockets import io.ktor.websocket.webSocket @@ -33,7 +30,6 @@ import kotlinx.html.* import org.slf4j.event.Level import redis.clients.jedis.JedisPool import redis.clients.jedis.Protocol -import java.net.URI import java.time.Duration import java.time.LocalDateTime @@ -250,10 +246,7 @@ fun Application.module() { } script { - val wsurl = call.url { - protocol = if (protocol.isSecure()) URLProtocol.WSS else URLProtocol.WS - path("/ws") - } + val wsurl = baseURL.replaceFirst("http", "ws") + "/ws?name=$who&type=${what.name}" unsafe { //language=JavaScript +""" @@ -325,6 +318,7 @@ fun Application.module() { for (frame in this.incoming.mapNotNull { it as? Frame.Text }) { try { val msg: RecvMsg = mapper.readValue(frame.readText()) + println(msg) val send = Message(what.let { if (it == Types.ask) who else "someone" }, msg.message) mms.addMessageTo(who, send) mms.getSocketsFor(who).forEach { @@ -355,8 +349,10 @@ fun Application.module() { } } +val baseURL = System.getenv("SQA_BASE_URL") ?: "http://localhost:8080" fun main() { + val host: String? = System.getenv("SQA_REDIS_HOST") val port: Int? = System.getenv("SQA_REDIS_PORT")?.toIntOrNull() mms = if (host != null) {