From d2c8d3dd20d18257bcc93a656672936fe8e965dd Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 24 Mar 2023 22:54:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20db=E3=81=AEurl=E3=81=AA=E3=81=A9?= =?UTF-8?q?=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/dev/usbharu/hideout/Application.kt | 7 +++---- src/main/kotlin/dev/usbharu/hideout/config/Config.kt | 4 ++-- src/main/resources/application.conf | 6 ++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index e5b64c34..e67e5b60 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -25,8 +25,7 @@ import org.jetbrains.exposed.sql.Database import org.koin.ktor.ext.inject import java.util.* -fun main(args: Array): Unit = - io.ktor.server.netty.EngineMain.main(args) +fun main(args: Array): Unit = io.ktor.server.netty.EngineMain.main(args) @Suppress("unused") // application.conf references the main function. This annotation prevents the IDE from marking it as unused. fun Application.module() { @@ -34,8 +33,8 @@ fun Application.module() { single { Database.connect( - url = "jdbc:h2:./test;MODE=POSTGRESQL", - driver = "org.h2.Driver", + url = environment.config.property("hideout.database.url").getString(), + driver = environment.config.property("hideout.database.driver").getString(), ) } single { diff --git a/src/main/kotlin/dev/usbharu/hideout/config/Config.kt b/src/main/kotlin/dev/usbharu/hideout/config/Config.kt index 02983747..fc4fe21b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/Config.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/Config.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper object Config { - var configData:ConfigData = ConfigData("", jacksonObjectMapper()) + var configData: ConfigData = ConfigData() } -data class ConfigData(val hostname:String,val objectMapper: ObjectMapper) +data class ConfigData(val hostname: String = "", val objectMapper: ObjectMapper = jacksonObjectMapper()) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 94b0ac0f..0a1d02eb 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -13,4 +13,10 @@ ktor { hideout { hostname = "https://localhost:8080" hostname = ${?HOSTNAME} + database { + url = "jdbc:h2:./test;MODE=POSTGRESQL" + driver = "org.h2.Driver" + username = "" + password = "" + } }