https://kotlinlang.org logo
#ktor
Title
k

katokay

06/29/2018, 11:40 PM
I was a little surprised, but I’m sure there’s a logical explanation for this. Parameter “name” is null inside the interceptor but not inside the route. Is there another way to do this kind of thing?
Copy code
fun main(args: Array<String>) {
    val server = embeddedServer(Netty, port = 9000) {
        intercept(ApplicationCallPipeline.Call) {
            val name = call.parameters["name"]
            proceed()
        }

        routing {
            get("/login/{name}") {
                val name = call.parameters["name"]
                call.respond("Hello $name")
            }
        }
    }
    server.start(wait = true)
}
1
📝 1
Was able to work around it by using the process described here. It feels like there should be a bit simpler way to do something like this though. https://ktor.io/advanced/pipeline/route.html
Ah, even easier than I thought.
Copy code
routing {
    intercept(...
}