Created
November 25, 2020 13:15
-
-
Save Yotamho/63c189970d95bbae633b74beaf093963 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
| package com.checkpoint.datatube.firehose | |
| import cats.effect.{Blocker, ExitCode, IO, IOApp} | |
| import org.http4s.{HttpRoutes, StaticFile} | |
| import org.http4s.dsl.io._ | |
| import org.http4s.implicits._ | |
| import scala.concurrent.ExecutionContext.global | |
| import org.http4s.server.Router | |
| import org.http4s.server.blaze.BlazeServerBuilder | |
| object ServerExample extends IOApp{ | |
| override def run(args: List[String]): IO[ExitCode] = { | |
| val server = for { | |
| service <- Blocker[IO].map { | |
| blocker => | |
| HttpRoutes.of[IO] { | |
| case GET -> Root => | |
| StaticFile.fromResource[IO]("swagger.yaml", blocker, None).getOrElseF(NotFound()) | |
| } | |
| } | |
| server <- BlazeServerBuilder[IO](global) | |
| .bindHttp(8080, "0.0.0.0") | |
| .withHttpApp(Router("/" -> service).orNotFound) | |
| .resource | |
| } yield server | |
| server | |
| .use(_ => IO.never) | |
| .as(ExitCode.Success) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment