Jetty.kt

  1. package com.hexagonkt.http.server.jetty

  2. import com.hexagonkt.http.server.*
  3. import com.hexagonkt.http.handlers.HandlerBuilder
  4. import com.hexagonkt.http.handlers.HttpHandler

  5. /**
  6.  * Create a Jetty server and start it. It is a shortcut to avoid passing the adapter.
  7.  *
  8.  * @param settings Server settings info .
  9.  * @param handlers List of [HttpHandler] handlers used in this server instance.
  10.  *
  11.  * @return The started [HttpServer] instance.
  12.  */
  13. fun serve(
  14.     settings: HttpServerSettings = HttpServerSettings(), handlers: HttpHandler
  15. ): HttpServer =
  16.     HttpServer(JettyServletAdapter(), handlers, settings).apply { start() }

  17. /**
  18.  * Create a Jetty server and start it. It is a shortcut to avoid passing the adapter.
  19.  *
  20.  * @param settings Server settings info.
  21.  * @param block Lambda to be used to create the list of [HttpHandler] handlers used in the server.
  22.  *
  23.  * @return The started [HttpServer] instance.
  24.  */
  25. fun serve(
  26.     settings: HttpServerSettings = HttpServerSettings(), block: HandlerBuilder.() -> Unit
  27. ): HttpServer =
  28.     HttpServer(JettyServletAdapter(), HandlerBuilder().apply { block() }.handler(), settings)
  29.         .apply { start() }