Skip to content

Instantly share code, notes, and snippets.

@hamsterready
Created July 14, 2020 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamsterready/6164104f6694a4bddae602a9b42ab06f to your computer and use it in GitHub Desktop.
Save hamsterready/6164104f6694a4bddae602a9b42ab06f to your computer and use it in GitHub Desktop.
object HttpServer {
def run(): ZIO[Blocking with Clock, Throwable, Unit] =
ZIO.runtime[Clock].flatMap { implicit rts =>
val dsl = Http4sDsl[Task]
import dsl._
val app = HttpRoutes.of[Task] {
case GET -> Root / "ping" => Ok("pong")
}
for {
//bec <- ZIO.access[Blocking](_.get.blockingExecutor.asEC)
bec <- blocking.blocking(ZIO.descriptor.map(_.executor.asEC))
_ <-
BlazeServerBuilder[Task](bec)
.bindHttp(8081, "0.0.0.0")
.withoutBanner
.withNio2(true)
.withHttpApp(app.orNotFound)
.serve
.compile
.drain
} yield ()
}
}
object MyApp extends App {
def run(args: List[String]): URIO[ZEnv, ExitCode] =
HttpServer
.run()
.exitCode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment