From 854d92381b0b49b603ae710ae8e99e62c2312318 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 30 Mar 2023 20:01:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ContentNegotiation=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 ++ .../kotlin/dev/usbharu/hideout/Application.kt | 33 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c6ffbfb9..2ee2e280 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,12 +46,14 @@ dependencies { implementation("io.insert-koin:koin-core:$koin_version") implementation("io.insert-koin:koin-ktor:$koin_version") implementation("io.insert-koin:koin-logger-slf4j:$koin_version") + implementation("io.ktor:ktor-client-logging-jvm:2.2.4") testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") implementation("io.ktor:ktor-client-core:$ktor_version") implementation("io.ktor:ktor-client-cio:$ktor_version") + implementation("io.ktor:ktor-client-content-negotiation:$ktor_version") } jib { diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index 6526f6ba..6536b160 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -1,8 +1,7 @@ package dev.usbharu.hideout import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.databind.DeserializationFeature +feat:import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.config.ConfigData @@ -15,9 +14,10 @@ import dev.usbharu.hideout.routing.* import dev.usbharu.hideout.service.* import io.ktor.client.* import io.ktor.client.engine.cio.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.plugins.logging.* +import io.ktor.serialization.jackson.* import io.ktor.server.application.* -import io.ktor.server.auth.* -import io.ktor.util.* import org.jetbrains.exposed.sql.Database import org.koin.ktor.ext.inject import java.util.* @@ -38,18 +38,33 @@ fun Application.module() { ConfigData( url = environment.config.propertyOrNull("hideout.url")?.getString() ?: environment.config.property("hideout.hostname").getString(), - objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) - .setSerializationInclusion(JsonInclude.Include.NON_EMPTY).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false) + objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) ) } - single { HttpClient(CIO) } + single { + HttpClient(CIO) { + install(ContentNegotiation) { + jackson { + enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + setSerializationInclusion(JsonInclude.Include.NON_EMPTY) + configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + } + } + install(Logging) { + logger = Logger.DEFAULT + level = LogLevel.HEADERS + } + } + } single { UserRepository(get()) } single { UserAuthRepository(get()) } single { UserAuthService(get(), get()) } single { UserService(get()) } single { ActivityPubService() } - single { ActivityPubUserService(get(), get(),get(),get()) } - single { WebFingerService(get(),get()) } + single { ActivityPubUserService(get(), get(), get(), get()) } + single { WebFingerService(get(), get()) } } configureKoin(module) val configData by inject()