Is it possible to install a feature dynamically? I’m looking into integrating a login feature through through an OAuth provider stating in its doc that endpoints should be fetch and not stored statically since they could (rarely) change over time. From what I see in the doc from Ktor, the OAuth configuration is done directly into the Application block and it’s static
a
Aleksei Tirman [JB]
06/24/2021, 9:34 AM
If you have a reference to an
Application
instance then you can install any feature there "dynamically". Here is an example:
Copy code
val feature = object : ApplicationFeature<ApplicationCallPipeline, Unit, Unit> {
override val key: AttributeKey<Unit> = AttributeKey("MyFeature")
override fun install(pipeline: ApplicationCallPipeline, configure: Unit.() -> Unit) {
pipeline.sendPipeline.intercept(ApplicationSendPipeline.Before) {
println("Requested URL is ${call.request.uri}")
}
}
}
fun main() {
val server = embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
routing {
get("/") {
call.respondText { "root" }
}
}
}
server.start()
server.application.install(feature)
}
j
jean
06/24/2021, 9:35 AM
alright, I was not sure if it was possible to do something like that. Thanks 🙂