mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-06-13 13:25:13 +00:00
28 lines
711 B
Kotlin
28 lines
711 B
Kotlin
|
package dev.inmo.micro_utils.ktor.server.configurators
|
||
|
|
||
|
import io.ktor.application.*
|
||
|
import io.ktor.routing.Route
|
||
|
import io.ktor.routing.Routing
|
||
|
import kotlinx.serialization.Contextual
|
||
|
import kotlinx.serialization.Serializable
|
||
|
|
||
|
@Serializable
|
||
|
class ApplicationRoutingConfigurator(
|
||
|
private val elements: List<@Contextual Element>
|
||
|
) : KtorApplicationConfigurator {
|
||
|
interface Element { operator fun Route.invoke() }
|
||
|
|
||
|
override fun Application.configure() {
|
||
|
try {
|
||
|
feature(Routing)
|
||
|
} catch (e: IllegalStateException) {
|
||
|
install(Routing) {
|
||
|
elements.forEach {
|
||
|
it.apply { invoke() }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|