Hello Folks,
I’m trying to start a ktor server which is dependent upon my application.conf file. I’m using embeddedServer with custom shutdown hook as below:
Copy code
fun main(args: Array<String>): Unit = runBlocking(Dispatchers.Default) {
embeddedServer(
Netty,
) { module() }.awaitShutdown()
}
fun Application.module(testing: Boolean = false) {
configureMonitoring()
configureRouting()
configureSerialization()
configureHTTP()
configureKoin()
statusPage()
}
But I’m not sure where to pass the args from conf file. I know I can use
fun main(args: Array<String>): Unit = EngineMain.main(args)
instead of embeddedServer but I’m not sure I can add custom shutdown hook to it. Can someone please help me for this?
✅ 1
a
August Lilleaas
09/19/2022, 5:46 PM
how are you reading the config file, and where do you need to pass it to?
p
Partho Paul
09/20/2022, 4:51 AM
@August Lilleaas While using
EngineMain.main(args)
implementation, I’m able to read the config via
environment.config.property(key).getString()
. Using the same for embeddedServer is not working and is throwing
io.ktor.server.config.ApplicationConfigurationException: Property ktor.api.customkey not found
a
August Lilleaas
09/20/2022, 6:40 AM
ah, right. That makes sense, I believe the difference between embeddedServer and EngineMain.main(..) is that with embeddedServer, you configure Ktor programmatically instead of by config file?
August Lilleaas
09/20/2022, 6:40 AM
you could use a library such as Typesafe Config to read a .conf file instead
p
Partho Paul
09/20/2022, 9:29 AM
@August Lilleaas Thanks for the hint. Was able to implement it as: