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.

31 lines
834 B

3 years ago
  1. package wow.doge.http4sdemo
  2. import cats.effect.ExitCode
  3. import cats.effect.Resource
  4. import monix.bio.BIOApp
  5. import monix.bio.Task
  6. import monix.bio.UIO
  7. import slick.jdbc.JdbcProfile
  8. import wow.doge.http4sdemo.SlickResource
  9. object Main extends BIOApp {
  10. val profile: JdbcProfile = _root_.slick.jdbc.H2Profile
  11. def app = for {
  12. db <- SlickResource("myapp.database")
  13. _ <- Resource.liftF(for {
  14. config <- JdbcDatabaseConfig.loadFromGlobal("myapp.database")
  15. _ <- DBMigrations.migrate(config)
  16. } yield ())
  17. _ <- Resource.liftF(
  18. Task.deferAction(implicit s =>
  19. Http4sdemoServer.stream(db, profile).compile.drain
  20. )
  21. )
  22. } yield ()
  23. def run(args: List[String]) = {
  24. app
  25. .use(_ => Task.never)
  26. .onErrorHandleWith(ex => UIO(ex.printStackTrace()))
  27. .as(ExitCode.Success)
  28. }
  29. }