I'm learing how to work with ktor. For a special use case i need to redirect to a different domain from my ktor server. However i cant get it to work rigth now.
As an simple example i have an Application.kt
import io.ktor.application.*
import io.ktor.http.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
fun main(args: Array<String>) {
val server = embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondRedirect("www.google.com")
}}
}
}
server.start(wait = true)
}
What i except is that it redirects me to www.google.com
however it redirects me to localhost:8080/www.google.com
Figured it out. You need to set also the protocol. This works
call.respondRedirect("https://google.com/")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With