okay so this should work again, but it's a lot more cursed now (Main.Kt#249)

This commit is contained in:
Julius 2019-12-11 20:59:15 +01:00
parent e63b07ed69
commit f61a115e32

View file

@ -12,9 +12,7 @@ import io.ktor.features.CallLogging
import io.ktor.features.ContentNegotiation import io.ktor.features.ContentNegotiation
import io.ktor.html.respondHtml import io.ktor.html.respondHtml
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.http.URLProtocol
import io.ktor.http.cio.websocket.* import io.ktor.http.cio.websocket.*
import io.ktor.http.isSecure
import io.ktor.jackson.jackson import io.ktor.jackson.jackson
import io.ktor.response.respondRedirect import io.ktor.response.respondRedirect
import io.ktor.response.respondText import io.ktor.response.respondText
@ -22,7 +20,6 @@ import io.ktor.routing.get
import io.ktor.routing.routing import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty import io.ktor.server.netty.Netty
import io.ktor.util.url
import io.ktor.websocket.DefaultWebSocketServerSession import io.ktor.websocket.DefaultWebSocketServerSession
import io.ktor.websocket.WebSockets import io.ktor.websocket.WebSockets
import io.ktor.websocket.webSocket import io.ktor.websocket.webSocket
@ -33,7 +30,6 @@ import kotlinx.html.*
import org.slf4j.event.Level import org.slf4j.event.Level
import redis.clients.jedis.JedisPool import redis.clients.jedis.JedisPool
import redis.clients.jedis.Protocol import redis.clients.jedis.Protocol
import java.net.URI
import java.time.Duration import java.time.Duration
import java.time.LocalDateTime import java.time.LocalDateTime
@ -250,10 +246,7 @@ fun Application.module() {
} }
script { script {
val wsurl = call.url { val wsurl = baseURL.replaceFirst("http", "ws") + "/ws?name=$who&type=${what.name}"
protocol = if (protocol.isSecure()) URLProtocol.WSS else URLProtocol.WS
path("/ws")
}
unsafe { unsafe {
//language=JavaScript //language=JavaScript
+""" +"""
@ -325,6 +318,7 @@ fun Application.module() {
for (frame in this.incoming.mapNotNull { it as? Frame.Text }) { for (frame in this.incoming.mapNotNull { it as? Frame.Text }) {
try { try {
val msg: RecvMsg = mapper.readValue(frame.readText()) val msg: RecvMsg = mapper.readValue(frame.readText())
println(msg)
val send = Message(what.let { if (it == Types.ask) who else "someone" }, msg.message) val send = Message(what.let { if (it == Types.ask) who else "someone" }, msg.message)
mms.addMessageTo(who, send) mms.addMessageTo(who, send)
mms.getSocketsFor(who).forEach { mms.getSocketsFor(who).forEach {
@ -355,8 +349,10 @@ fun Application.module() {
} }
} }
val baseURL = System.getenv("SQA_BASE_URL") ?: "http://localhost:8080"
fun main() { fun main() {
val host: String? = System.getenv("SQA_REDIS_HOST") val host: String? = System.getenv("SQA_REDIS_HOST")
val port: Int? = System.getenv("SQA_REDIS_PORT")?.toIntOrNull() val port: Int? = System.getenv("SQA_REDIS_PORT")?.toIntOrNull()
mms = if (host != null) { mms = if (host != null) {