> I think that's probably about as clean as you...
# http4k
a
I think that's probably about as clean as you can get it barring some tweaking
Yeah, that's what I suspected. Thanks for clarifying.
you'd want to just implement a new version of
RoutingHttpHandler
That's what I was hoping to avoid 😇 . I don't really understand this class yet, but perhaps I'll have to muscle through it.
d
you can recreate the routing tree at request time without a problem, and then just stick it inside another HttpHandler which captures all traffic
should be trivial really.. 🙂
🤓 1
Copy code
fun List<Int>.buildRoutes() = routes(
    map {
        { r: Request -> r.uri.port == it }.asRouter() bind JavaHttpClient()
    }
)

fun handler(ports: List<Int>) {
    { req: Request -> ports.buildRoutes()(req) }.asServer(SunHttp(8080)).start()
}
a
Ah yes, I see now. Thanks!
d
you'll also need this:
Copy code
fun routes(routers: List<RoutingHttpHandler>): RoutingHttpHandler = routes(*routers.toTypedArray())
I'm adding that to http4k now
👍 1