Hi all, good day. I would like to ask if someone k...
# ktor
f
Hi all, good day. I would like to ask if someone know if its possible to run a ktor service with two different ports (and set of routes) so, for example, I can have the metrics scrapper running on a separate port) . I tried looking at the docs but could not figure out a way of doing that.
s
Afaik you should be able to spin up 2x
embeddedServer
using the
Netty
engine but bound to different ports. For example:
Copy code
fun main() = runBlocking<Unit> {
  launch {
   embeddedServer(Netty, port = 8080) {
     // install routes
   }
  }
  launch {
   embeddedServer(Netty, port = 8081) {
     // install other routes
   }
  }
}
If that doesn't work
embeddedServer
I'd consider it bugged.
f
is it possible using HOCON configuration file instead of code ?
a
Also, you can configure multiple ports for the same server instance and match routes by a specific port. Unfortunately, you can’t configure it via a configuration file.
Copy code
embeddedServer(Netty, applicationEngineEnvironment {
    connector {
        port = 8080
    }

    connector {
        port = 8081
    }

    module {
        routing {
            port(8081) {
                get {

                }
            }
        }
    }
}).start()
f
yes, thats exactly what I want… mmm.. but no configuration file is a bummer 😫