Hello All, was wondering if anyone would be able t...
# ktor
m
Hello All, was wondering if anyone would be able to help be understand configuration with ktor. I’m currently running the server via EngineMain and I’d like to be able to get properties from my application.conf elsewhere in my application. Which I’ve been able to do using
val config = HoconApplicationConfig(ConfigFactory.load())
but that seems to only load the application.conf from resources. Is there a way to get that sort of functionality but also have it work when supplying a conf file using the
-config=application-prod.conf
argument when running the server? If anyone would be willing to steer me in the right direction, I’d highly appreciate it. Thanks!
f
I'm running a pretty outdated version, but I used the
environment.config
property in my
Application.main()
function to get a reference to the loaded configuration and then injected this in my resources, I guess something like this should still work
👍 1
m
You can also just opt out of the built in config and do something else. That’s what I do - then you have total freedom to arrange your config files (or other config sources) however you please
👍 1
💯 1
1
m
@fred.deschenes Ah perfect, that got me far enough to get a quick fix in. @mp I think in the long run your solution is better. Right now I'm learning both Kotlin and ktor, once I get more familiar I think I'll end up taking the more custom route. Thanks!
m
Makes sense. When you feel like exploring a bit, here’s one way to do config yourself: https://bitbucket.org/marshallpierce/ktor-demo/src/master/
👍 1
The point is not that you should do it exactly the way that demo project does it (though it is a perfectly reasonable config system) — the point is that it’s probably easier than you think to do it yourself.