Hi All, I am new to http4k, some nice concepts. I ...
# http4k
d
Hi All, I am new to http4k, some nice concepts. I need to be able to configure the server (Jetty) from ENV variables. I know of being able to inject the port via ENV etc. I need to be able start the server from a custom config and the add the routes which extend RoutingHttpHnadler. My issue is getting the ServerConfig right so that when I start the server it stays running. What I am looking for is a full blown example rather than code snippets. This is my ServerConfig:
Copy code
class JettyConfig(private val port: Int) : ServerConfig {

    override fun toServer(http: HttpHandler): Http4kServer {
        val server = Server().apply {
            insertHandler(http.toJettyHandler())
        }

        return object : Http4kServer {
            override fun start(): Http4kServer = apply { server.start() }

            override fun stop(): Http4kServer = apply { server.stop() }

            override fun port(): Int = port
        }
    }


}
And Called using
App.app.asServer(JettyConfig(App.port)).start()
d
You shouldn't need to create your own ServerConfig unless you really want something niche. Just plug into the version you want by importing
http4k-server-xyz
the module. There are plenty of examples in here, including using
http4k-config
for typesafe configuration: https://github.com/http4k/examples https://github.com/http4k/http4k-by-example
d
indirectly related question - when I need more server specific metrics for opentelemetry do I need then a customized ServerConfig or can I solve that differently?
d
I suspect you'll need something customised
d
to bad 😄 but thanks anyways - sometimes it's hard when you got compared with other teams simply using spring 😞 they don't understand the benefits we gained 🚀
d
@DanielZ I guess that understanding your software isn't too trendy nowadays.. 😂
🤣 2
d
I have managed to achieve most of want I needed from the TDD example. Again not the best, is ther a blog post tutorial that goes with it.
It still seems like we need a better tutorial example for ServerConfig usage.
What do you need a custom server for? it's fairly rare that we need to create one, especially when just starting out