You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package wow.doge.http4sdemo
  2. import cats.implicits._
  3. import fs2.Stream
  4. import monix.bio.Task
  5. import monix.execution.Scheduler
  6. import org.http4s.client.blaze.BlazeClientBuilder
  7. import org.http4s.implicits._
  8. import org.http4s.server.blaze.BlazeServerBuilder
  9. import org.http4s.server.middleware.Logger
  10. import slick.jdbc.JdbcBackend.DatabaseDef
  11. import slick.jdbc.JdbcProfile
  12. import wow.doge.http4sdemo.services.LibraryDbio
  13. import wow.doge.http4sdemo.services.LibraryServiceImpl
  14. object Http4sdemoServer {
  15. def stream(
  16. db: DatabaseDef,
  17. p: JdbcProfile
  18. )(implicit s: Scheduler): Stream[Task, Nothing] = {
  19. for {
  20. client <- BlazeClientBuilder[Task](s).stream
  21. helloWorldAlg = HelloWorld.impl
  22. jokeAlg = Jokes.impl(client)
  23. // Combine Service Routes into an HttpApp.
  24. // Can also be done via a Router if you
  25. // want to extract a segments not checked
  26. // in the underlying routes.
  27. libraryDbio = new LibraryDbio(p)
  28. libraryService = new LibraryServiceImpl(p, libraryDbio, db)
  29. httpApp = (
  30. Http4sdemoRoutes.helloWorldRoutes[Task](helloWorldAlg) <+>
  31. Http4sdemoRoutes.jokeRoutes[Task](jokeAlg) <+>
  32. Http4sdemoRoutes.libraryRoutes(libraryService)
  33. ).orNotFound
  34. // With Middlewares in place
  35. finalHttpApp = Logger.httpApp(true, true)(httpApp)
  36. // _ = {finalHttpApp.run(Request.)}
  37. exitCode <- BlazeServerBuilder[Task](s)
  38. .bindHttp(8081, "0.0.0.0")
  39. .withHttpApp(finalHttpApp)
  40. .serve
  41. } yield exitCode
  42. }.drain
  43. }