From f5a5330e93390d761e9c5076eb2614eed0f42099 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 27 Nov 2020 20:41:01 +0600 Subject: [PATCH] publishing keys repo ktor server route now is optional --- .../PublishingKeysRepoRoutingConfigurator.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/PublishingKeysRepoRoutingConfigurator.kt b/publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/PublishingKeysRepoRoutingConfigurator.kt index 356a7e33..cea7997d 100644 --- a/publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/PublishingKeysRepoRoutingConfigurator.kt +++ b/publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/PublishingKeysRepoRoutingConfigurator.kt @@ -6,19 +6,25 @@ import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigur import io.ktor.routing.Route import io.ktor.routing.route +private inline fun configurator(proxyTo: PublishingKeysRepo): Route.() -> Unit = { + configureReadPublishingKeysRepoRoutes(proxyTo) + configureWritePublishingKeysRepoRoutes(proxyTo) +} + fun Route.configurePublishingKeysRepoRoutes ( - proxyTo: PublishingKeysRepo + proxyTo: PublishingKeysRepo, + rootRoute: String? = publishingKeysRootRoute ) { - route(publishingKeysRootRoute) { - configureReadPublishingKeysRepoRoutes(proxyTo) - configureWritePublishingKeysRepoRoutes(proxyTo) - } + rootRoute ?.also { + route(it, configurator(proxyTo)) + } ?: configurator(proxyTo).invoke(this) } class PublishingKeysRepoRoutingConfigurator ( - private val proxyTo: PublishingKeysRepo + private val proxyTo: PublishingKeysRepo, + private val rootRoute: String? = publishingKeysRootRoute ) : ApplicationRoutingConfigurator.Element { override fun Route.invoke() { - configurePublishingKeysRepoRoutes(proxyTo) + configurePublishingKeysRepoRoutes(proxyTo, rootRoute) } } \ No newline at end of file