Last active
January 23, 2022 13:28
-
-
Save dragneelfps/e3a2142d1b941da0b87c2d0bfd1c8bff to your computer and use it in GitHub Desktop.
Replicating `spring.active.profiles`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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