Created
December 3, 2018 09:48
-
-
Save globulon/e69502defe53e3bfa54e35eb900618a1 to your computer and use it in GitHub Desktop.
This file contains 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
import akka.http.scaladsl.Http | |
import akka.http.scaladsl.Http.ServerBinding | |
import com.graboids.alpha.service.users.app.Application | |
import com.graboids.alpha.service.users.config.resolveConfig | |
import com.graboids.config.hocon._ | |
import com.graboids.fp._ | |
import scalaz.NonEmptyList._ | |
import scalaz.ioeffect.console._ | |
import scalaz.ioeffect.{IO, SafeApp, Void} | |
import scala.concurrent.Future | |
object Users extends Routes with Environment with SafeApp { | |
def run(args: List[String]): IO[Void, ExitStatus] = | |
process.attempt.map(_.fold(_ => 1, _ => 0)).map { | |
case code if code > 0 ⇒ ExitStatus.ExitNow(code) | |
case _ ⇒ ExitStatus.DoNotExit | |
} | |
private def process: IO[AppErrs, Unit] = for { | |
_ ← putStrLn(line = "Starting Server").leftMap[AppErrs](ex ⇒ nels(ThrownError(ex.getMessage))) | |
app ← resolveApplication.io | |
_ ← startHttp(app) | |
_ ← putStrLn(line = "Server Started on port 8080").leftMap[AppErrs](ex ⇒ nels(ThrownError(ex.getMessage))) | |
} yield () | |
private def startHttp[A](app: Application): IO[AppErrs, Future[ServerBinding]] = | |
IO.sync(Http().bindAndHandle(routes(app), "0.0.0.0", 8080)) | |
private def resolveApplication: Safe[Application] = (resolveConfig map Application) =<< fromEnv | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment