feat: ContentNegotiationを追加

This commit is contained in:
usbharu 2023-03-30 20:01:04 +09:00
parent 9db38fc4e0
commit 854d92381b
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
2 changed files with 26 additions and 9 deletions

View File

@ -46,12 +46,14 @@ dependencies {
implementation("io.insert-koin:koin-core:$koin_version") implementation("io.insert-koin:koin-core:$koin_version")
implementation("io.insert-koin:koin-ktor:$koin_version") implementation("io.insert-koin:koin-ktor:$koin_version")
implementation("io.insert-koin:koin-logger-slf4j:$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("io.ktor:ktor-server-tests-jvm:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
implementation("io.ktor:ktor-client-core:$ktor_version") implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version") implementation("io.ktor:ktor-client-cio:$ktor_version")
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
} }
jib { jib {

View File

@ -1,8 +1,7 @@
package dev.usbharu.hideout package dev.usbharu.hideout
import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonGenerator feat:import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.config.Config
import dev.usbharu.hideout.config.ConfigData import dev.usbharu.hideout.config.ConfigData
@ -15,9 +14,10 @@ import dev.usbharu.hideout.routing.*
import dev.usbharu.hideout.service.* import dev.usbharu.hideout.service.*
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.engine.cio.* 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.application.*
import io.ktor.server.auth.*
import io.ktor.util.*
import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.Database
import org.koin.ktor.ext.inject import org.koin.ktor.ext.inject
import java.util.* import java.util.*
@ -39,17 +39,32 @@ fun Application.module() {
url = environment.config.propertyOrNull("hideout.url")?.getString() url = environment.config.propertyOrNull("hideout.url")?.getString()
?: environment.config.property("hideout.hostname").getString(), ?: environment.config.property("hideout.hostname").getString(),
objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false) .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
) )
} }
single<HttpClient> { HttpClient(CIO) } single<HttpClient> {
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<IUserRepository> { UserRepository(get()) } single<IUserRepository> { UserRepository(get()) }
single<IUserAuthRepository> { UserAuthRepository(get()) } single<IUserAuthRepository> { UserAuthRepository(get()) }
single<IUserAuthService> { UserAuthService(get(), get()) } single<IUserAuthService> { UserAuthService(get(), get()) }
single<UserService> { UserService(get()) } single<UserService> { UserService(get()) }
single<ActivityPubService> { ActivityPubService() } single<ActivityPubService> { ActivityPubService() }
single<ActivityPubUserService> { ActivityPubUserService(get(), get(),get(),get()) } single<ActivityPubUserService> { ActivityPubUserService(get(), get(), get(), get()) }
single<IWebFingerService> { WebFingerService(get(),get()) } single<IWebFingerService> { WebFingerService(get(), get()) }
} }
configureKoin(module) configureKoin(module)
val configData by inject<ConfigData>() val configData by inject<ConfigData>()