Hello there.
Is there any option to run ktor app that is listening in multiple ports and every port mounting a different module? Could I configure it with HOCON?
I would like to share the same project (Same logic in almost all endpoints) but with different properties (db, cache...)
For that I would like to have something like:
Copy code
fun Application.moduleAdmin() { // This module listening on port 8090
routing {
get("/") {
call.respondText("This is the admin module")
}
}
}
fun Application.moduleA() { // This module listening on port 8080
routing {
get("/") {
call.respondText("This is the module A")
}
}
}
fun Application.moduleB() { // This module listening on port 8081
routing {
get("/") {
call.respondText("This is the module B")
}
}
}
b
Big Chungus
12/22/2021, 8:49 AM
You could start multiple Application instances in your main and load hocon files for each manually. I don't think you can have multiple ports assigned to the same Application instance, though.
👍 2
j
jcminarro
12/22/2021, 9:16 AM
Could I start multiple EmbebbedServer on one app (Every one listening on a different port)?
Would it be better (CPU, Mem...) than run multiple application instances?
b
Big Chungus
12/22/2021, 9:16 AM
Sorry, yes. That's exactly what I meant 😀
a
Aleksei Tirman [JB]
12/22/2021, 10:26 AM
You can have a single application listening for multiple ports but there is no way to bind them to different modules.
j
jcminarro
12/22/2021, 10:51 AM
What is the motivation for that? 🤔
Why would I want to have the same app listening on multiple ports (apart of handling http/https request)