Skip to content

Instantly share code, notes, and snippets.

@dragneelfps
Last active January 23, 2022 13:28
Show Gist options
  • Save dragneelfps/e3a2142d1b941da0b87c2d0bfd1c8bff to your computer and use it in GitHub Desktop.
Save dragneelfps/e3a2142d1b941da0b87c2d0bfd1c8bff to your computer and use it in GitHub Desktop.
Replicating `spring.active.profiles`
fun profileAwareConfig(): Config {
val logger = LoggerFactory.getLogger("ProfileAwareConfig")
val profiles = (System.getProperty("ktor.active.profiles") ?: "").split(",")
val combinedConfig = profiles.fold(ConfigFactory.defaultApplication()) { config, profile ->
val profileConfig = ConfigFactory.parseResourcesAnySyntax("application-$profile")
profileConfig.withFallback(config)
}
if (logger.isDebugEnabled) {
logger.debug(combinedConfig.root().render())
}
return ConfigFactory.load(combinedConfig)
}
fun main() {
embeddedServer(Netty, applicationEngineEnvironment {
config = HoconApplicationConfig(profileAwareConfig())
connector {
port = config.property("ktor.deployment.port").getString().toInt()
}
module {
mainModule()
}
}).start(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment