Skip to content

Commit

Permalink
Do not start server if no config file can be found or read
Browse files Browse the repository at this point in the history
  • Loading branch information
pklimai committed Nov 27, 2024
1 parent d289f64 commit 87ed2c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/jvmMain/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import org.postgresql.util.PSQLException
import java.io.File
import java.sql.DriverManager

lateinit var config: ConfigFile

fun Application.main() {

val config = readConfig()

install(DefaultHeaders)
install(CallLogging)
install(ContentNegotiation) {
Expand Down Expand Up @@ -415,4 +414,7 @@ fun Application.main() {
}

// See resources/application.conf for ktor configuration
fun main(args: Array<String>) = io.ktor.server.netty.EngineMain.main(args)
fun main(args: Array<String>) {
config = readConfig() ?: return
io.ktor.server.netty.EngineMain.main(args)
}
4 changes: 2 additions & 2 deletions src/jvmMain/kotlin/config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.io.File

const val CONFIG_PATH = "./ems.config.yaml"

fun readConfig(): ConfigFile {
fun readConfig(): ConfigFile? {
val mapper = ObjectMapper(YAMLFactory()).also { it.findAndRegisterModules() }

val config: ConfigFile
Expand All @@ -17,7 +17,7 @@ fun readConfig(): ConfigFile {
"Could not read config file from $CONFIG_PATH. \n" +
"Make sure the file is there and has proper format (if in Docker, mount as volume)"
)
throw e
return null
}
println("Done reading config from $CONFIG_PATH")
return config
Expand Down

0 comments on commit 87ed2c0

Please sign in to comment.