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

Barry Fawthrop

09/08/2021, 10:34 PM
Anyone know of an example/tutorial for a ktor rest server that uses productflavors so you can have different configuration variables for QA and production environments. Thanks
ł

Łukasz Bednarczyk

09/09/2021, 4:55 AM
Read about the HOCON file. You don’t need flavours 😉
a

Aleksei Tirman [JB]

09/09/2021, 7:59 AM
You can use environment variables to configure each stage differently. Here you can find an information about taking values for parameters from environment variables in HOCON configuration.
b

Barry Fawthrop

09/15/2021, 5:54 PM
Thanks guys. But I’m still not seeing how the Hocon file allows for diff configurations. I’m needs host =qa.example.com for one and host.example.com for another Thanks
a

Aleksei Tirman [JB]

09/16/2021, 7:37 AM
@Barry Fawthrop could you please describe how the host is used in your Ktor application?
b

Barry Fawthrop

09/16/2021, 11:54 AM
Host is the database sever(clusters) one for dev, one for was and one for prod
ł

Łukasz Bednarczyk

09/16/2021, 12:03 PM
ok, so…where is the problem? You can define in HOCON file something like this:
Copy code
ktor {
    environment = ${?KTOR_ENV}

    qa {
        host= xaxa
    }

    dev {
        host= dudu
    }
}
When you start your app, you have to define which config should start (qa or dev).
@Barry Fawthrop You can also load different files with config depending on env
b

Barry Fawthrop

09/16/2021, 12:09 PM
Thanks Lukasz, “when you start your app” you mean a command line parameter like —env = prod, right?
ł

Łukasz Bednarczyk

09/16/2021, 12:13 PM
yeah
b

Barry Fawthrop

09/16/2021, 12:14 PM
Thank you
😇 1
2 Views