Created
July 14, 2020 13:05
-
-
Save hamsterready/6164104f6694a4bddae602a9b42ab06f 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 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