Skip to content

Commit

Permalink
Add a health check
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajkapica committed Jun 22, 2024
1 parent 41a7f99 commit 87c6dd9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
9 changes: 3 additions & 6 deletions api/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ resolvers += "Akka library repository" at "https://repo.akka.io/maven"

enablePlugins(JavaAppPackaging)

val scalatestVersion = "3.2.18"
val AkkaVersion = "2.9.3"
val AkkaHttpVersion = "10.6.3"
val MongoDBVersion = "5.1.0"
libraryDependencies ++= {
Seq(
"org.scalatest" %% "scalatest" % scalatestVersion % "test",
"org.scalatest" %% "scalatest" % "3.2.18" % "test",
"com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http" % "10.6.3",
"org.slf4j" % "slf4j-simple" % "2.0.13",
)
}
libraryDependencies += ("org.mongodb.scala" %% "mongo-scala-driver" % MongoDBVersion).cross(
libraryDependencies += ("org.mongodb.scala" %% "mongo-scala-driver" % "5.1.0").cross(
CrossVersion.for3Use2_13
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import akka.http.scaladsl.server.Directives.get
import akka.http.scaladsl.server.Directives.path
import akka.http.scaladsl.server.Route

object Routes {
object Router {

val route: Route =
path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
}
}
path("health") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>OK</h1>"))
}
}

}
30 changes: 12 additions & 18 deletions api/src/main/scala/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@ import scala.concurrent.duration.Duration
object Server {

def run() =
while (true) {
println("Hello, world!")
Thread.sleep(1000)
}
// implicit val system = ActorSystem(Behaviors.empty, "my-system")
// implicit val executionContext = system.executionContext
// val keepAlive = Promise[Unit].future
//
// val host = "0.0.0.0"
// val port = 8080
//
// val bindingFuture = Http()
// .newServerAt(host, port)
// .bind(Routes.route)
//
// Database.test()
//
// Await.result(keepAlive, Duration.Inf)
implicit val system = ActorSystem(Behaviors.empty, "api")
implicit val executionContext = system.executionContext

val host = "0.0.0.0"
val port = 8080

val bindingFuture = Http()
.newServerAt(host, port)
.bind(Router.route)

val keepAlive = Promise[Unit].future
Await.result(keepAlive, Duration.Inf)

}

0 comments on commit 87c6dd9

Please sign in to comment.