Hello there. Is there any option to run ktor app t...
# ktor
j
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
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
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
Sorry, yes. That's exactly what I meant 😀
a
You can have a single application listening for multiple ports but there is no way to bind them to different modules.
j
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)