I have the fake for a TCP reverse proxy, where eac...
# http4k
a
I have the fake for a TCP reverse proxy, where each port forwards requests to a different fake IOT device. There's also a control api with a static port (or
null
in the fake scenario).
Copy code
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.