https://kotlinlang.org logo
#ktor
Title
# ktor
v

voben

05/19/2019, 9:28 PM
Hi, I have created 2 Hocon files. One for dev and one for prod. When running the application, I am currently setting the dev config file like this
io.ktor.server.netty.EngineMain.main(arrayOf("-config=dev.conf"))
. Is it possible for the appropriate file to be set automatically based on my environment? How do I detect what environment I am in to be able to set the config file?
g

gildor

05/20/2019, 1:28 AM
You can use environment variable to set required config
One more approach is to have specify special server runner for dev environment and specify different config
v

voben

05/20/2019, 2:49 AM
Thanks for your response Andrey, but using environment variables doesn’t allow me to change my config file. It only allows me to read the variables in the already loaded config file. Also what do you mean by specify a special server runner. Could you elaborate on how to do this?
g

gildor

05/20/2019, 5:16 AM
You can change config file, because hocon files support environment variables, see doc which I sent above, you can just read env var if it available
About runner, I mean that depending how you start your server, you can just have 2 different tasks/commands to run it with different arguments
Also, after all, you free to load any config file manually, it's not necessary to use standard application.conf file, and use any loading logic as you want