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

a8tb1117

02/09/2023, 4:02 PM
Hello. I am creating a sample app that serves both frontend and backend on different ports. I am looking at this code: https://github.com/ktorio/ktor-documentation/blob/2.2.3/codeSnippets/snippets/cors/src/main/kotlin/com/example/Application.ktThis and it uses embedded server. I want to use application.conf. Can anyone help me achieve it?
a

Aleksei Tirman [JB]

02/09/2023, 4:05 PM
You can read about it in the documentation.
a

a8tb1117

02/09/2023, 4:33 PM
It doesn't have multiple port specification. It seems if i use application.conf, my server is only listening to one port.
Hello @Aleksei Tirman [JB]. it's been a while but let me ask the same question in a different way. Is there any way to listen to two ports when i start the server using application.conf? I just wanted to do the following // in Application.kt fun main(args: Array<String>) { val env = applicationEngineEnvironment { module { backend() frontend() } connector { host = "0.0.0.0" port = 8080 } connector { host = "0.0.0.0" port = 3000 } } embeddedServer(Netty, env).start(true) } using application.conf. So, something I expected working was: // Application.kt: fun main(args: Array<String>) : Unit = EngineMain.main(args) // application.conf: ktor { deployment { port = 8080 host = "0.0.0.0" } deployment { port = 3000 host = "0.0.0.0" } application { modules = [ com.sample.ApplicationKt.backend, com.sample.ApplicationKt.frontend ] } } Thanks.
a

Aleksei Tirman [JB]

02/20/2023, 12:23 PM
Unfortunately, that’s not possible.
👍 1
18 Views