Created
October 18, 2018 14:02
-
-
Save Pyppe/aa032a965588eceb0fae9f6989460085 to your computer and use it in GitHub Desktop.
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 characters
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() | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment