add configurators for ktor server
This commit is contained in:
parent
03e0728fdf
commit
46c84099be
41
core/ktor/server/build.gradle
Normal file
41
core/ktor/server/build.gradle
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||||
|
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
project.version = "$core_version"
|
||||||
|
project.group = "com.insanusmokrassar"
|
||||||
|
|
||||||
|
apply plugin: "java-library"
|
||||||
|
apply plugin: "kotlin"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
api projectByName("postssystem.core.ktor.common")
|
||||||
|
api projectByName("postssystem.ktor.server")
|
||||||
|
|
||||||
|
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.ktor.server.configurators
|
||||||
|
|
||||||
|
import io.ktor.application.Application
|
||||||
|
import io.ktor.application.install
|
||||||
|
import io.ktor.features.CachingHeaders
|
||||||
|
import kotlinx.serialization.ContextualSerialization
|
||||||
|
|
||||||
|
data class ApplicationCachingHeadersConfigurator(
|
||||||
|
private val elements: List<@ContextualSerialization Element>
|
||||||
|
) : KtorApplicationConfigurator{
|
||||||
|
interface Element { operator fun CachingHeaders.Configuration.invoke() }
|
||||||
|
|
||||||
|
override fun Application.configure() {
|
||||||
|
install(CachingHeaders) {
|
||||||
|
elements.forEach {
|
||||||
|
it.apply { invoke() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.ktor.server.configurators
|
||||||
|
|
||||||
|
import io.ktor.application.*
|
||||||
|
import io.ktor.routing.Routing
|
||||||
|
import kotlinx.serialization.ContextualSerialization
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class ApplicationRoutingConfigurator(
|
||||||
|
private val elements: List<@ContextualSerialization Element>
|
||||||
|
) : KtorApplicationConfigurator {
|
||||||
|
interface Element { operator fun Routing.invoke() }
|
||||||
|
|
||||||
|
override fun Application.configure() {
|
||||||
|
try {
|
||||||
|
feature(Routing)
|
||||||
|
} catch (e: IllegalStateException) {
|
||||||
|
install(Routing) {
|
||||||
|
elements.forEach {
|
||||||
|
it.apply { invoke() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.ktor.server.configurators
|
||||||
|
|
||||||
|
import io.ktor.application.Application
|
||||||
|
import io.ktor.application.install
|
||||||
|
import io.ktor.sessions.Sessions
|
||||||
|
import kotlinx.serialization.ContextualSerialization
|
||||||
|
|
||||||
|
class ApplicationSessionsConfigurator(
|
||||||
|
private val elements: List<@ContextualSerialization Element>
|
||||||
|
) : KtorApplicationConfigurator {
|
||||||
|
interface Element { operator fun Sessions.Configuration.invoke() }
|
||||||
|
|
||||||
|
override fun Application.configure() {
|
||||||
|
install(Sessions) {
|
||||||
|
elements.forEach {
|
||||||
|
it.apply { invoke() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.ktor.server.configurators
|
||||||
|
|
||||||
|
import io.ktor.application.Application
|
||||||
|
|
||||||
|
interface KtorApplicationConfigurator {
|
||||||
|
fun Application.configure()
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.ktor.server.configurators
|
||||||
|
|
||||||
|
import io.ktor.application.Application
|
||||||
|
import io.ktor.application.install
|
||||||
|
import io.ktor.features.StatusPages
|
||||||
|
import kotlinx.serialization.ContextualSerialization
|
||||||
|
|
||||||
|
class StatusPagesConfigurator(
|
||||||
|
private val elements: List<@ContextualSerialization Element>
|
||||||
|
) : KtorApplicationConfigurator {
|
||||||
|
interface Element { operator fun StatusPages.Configuration.invoke() }
|
||||||
|
|
||||||
|
override fun Application.configure() {
|
||||||
|
install(StatusPages) {
|
||||||
|
elements.forEach {
|
||||||
|
it.apply { invoke() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ String[] includes = [
|
|||||||
':core:ktor',
|
':core:ktor',
|
||||||
':core:ktor:common',
|
':core:ktor:common',
|
||||||
':core:ktor:client',
|
':core:ktor:client',
|
||||||
|
':core:ktor:server',
|
||||||
|
|
||||||
':publishing:api',
|
':publishing:api',
|
||||||
':publishing:exposed',
|
':publishing:exposed',
|
||||||
|
Loading…
Reference in New Issue
Block a user