Created
October 18, 2018 14:02
Revisions
-
Pyppe created this gist
Oct 18, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ object Http4sBlazeServerBuilder { case class Server(fiber: Fiber[IO, Nothing]) { def shutdownNow(): Unit = fiber.cancel.unsafeRunSync() } type MappedService = (String, HttpRoutes[IO]) private implicit val cs = IO.contextShift(ExecutionContext.Implicits.global) def startServer(port: Int, monitoringOrdinals: Option[DevOpsController.FlowOrdinalF] = None) (services: MappedService*): Server = { DevOpsMetrics.registerDefaultMetrics() val withPrometheusMetrics = PrometheusMetrics[IO](CollectorRegistry.defaultRegistry, prefix = "tmnow_http_server") val mappings: List[MappedService] = { ("/devops/internal", DevOpsController.createService(monitoringOrdinals)) :: services.toList } Server( BlazeServerBuilder[IO]. bindHttp(port, "0.0.0.0"). withIdleTimeout(5.minutes). withHttpApp( IORequestLogger( withPrometheusMetrics( Router[IO](mappings: _*) ).unsafeRunSync.orNotFound ) ). resource. use(_ => IO.never). start. unsafeRunSync() ) } }