Hi everybody, I have a project based on <#C0A974TJ...
# server
h
Hi everybody, I have a project based on #ktor v1.0.0-beta-4. It’s an API, exposing a big catalog (35 Mo). I am planning to bring this catalog into pieces later on but right now, it goes to production as this, in the form of a big String. I have some memory performance issues and I try to fix those issues. My App has the same configuration than during the Dev. I am looking for a way to have 2 separate configuration, one for dev and one for prod. I have read the documentation (https://ktor.io/servers/configuration/environments.html) but I can’t find a way to disable the autoreload conf I have set up in my app for dev purpose. Do you know how to do it ?
m
It's easy if you just have a main method that calls `embeddedServer`: do whatever you like to load config however you please (read from files, env vars, etc) and set up the server appropriately
FWIW the way I do it is to use a commons-config composite config that lets you easily mix multiple sources of config. If there are env vars specified, that overrides what's in properties files, etc. In production, config comes from env vars, and in local dev, properties files.
h
Your ways, I don’t know how to disable the autoreload part of my Hocon property file when I am in a Prod configuration mod.
m
I'm saying to simply not use hocon for everything so that you can have more control over how config is done.
h
I understand but as I am using ‘io.ktor.server.netty.EngineMain.main(args)’ I can’t find in the documentation how to set up watch by code. I can see it if I am using an embeddedServer.
Do I have to change from Engine Main to Embeded Server ?
m
Ah, I see. You would do it like so:
Copy code
val server = embeddedServer(Netty, port = whateverPortYouWant) {
    install(someKtorFeature)
}

server.start(wait = true)
I haven't tried using watch mode myself as I do not use that in my workflow, so I don't have a specific setup snippet for that
h
@mp Thanks a lot for your help ! I try
👍 1
m
Here's a snippet to load config data from env vars and optionally a directory of properties files, in case it helps.
Copy code
val composite = CompositeConfiguration()
    composite.addConfiguration(EnvironmentConfiguration())

    if (configDir != null) {
        Files.newDirectoryStream(Paths.get(configDir))
                .filter { p -> p.extension == "properties" }
                .toList()
                .sorted()
                // CompositeConfiguration looks at the first config first
                .reversed()
                .forEach { p ->
                    logger.trace("Loading config from $p")
                    val props = PropertiesConfiguration().apply {
                        encoding = StandardCharsets.UTF_8.name()
                        isDelimiterParsingDisabled = true
                    }
                    Files.newInputStream(p).use { i ->
                        props.load(i)
                    }
                    composite.addConfiguration(props)
                }
    }
1
I use that with https://github.com/brianm/config-magic/ to get strongly typed access to config data