Andrew O'Hara
01/05/2024, 3:03 PMnull
in the fake scenario).
val devices = mutableMapOf<Int, HttpHandler>()
val proxyApp = routes(
{ r: Request -> r.uri.port == null }.asRouter() bind controlApi,
{ r: Request -> r.uri.port in devices }.asRouter() bind { request ->
devices[request.uri.port]!!.invoke(request)
}
)
Is there a nicer way to do this? I understand it's not typical for an HttpHandler
to be listening to multiple ports at once (the real server is actually raw Netty), but perhaps there's some more advanced routing-fu.
I'm also interested if there's a built-in way to build a dynamic reverse proxy in general; i.e. a reverse proxy where I can add routes at runtime.