From 0f1783a61ea849e3a6d67a826d15e12b47fc565b Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Tue, 7 May 2024 20:56:08 +0700 Subject: [PATCH] Add app with http4s module --- build.sbt | 23 +++++++++++- modules/app/src/main/scala/app.config.scala | 41 +++++++++++++++++++++ project/Dependencies.scala | 41 +++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 modules/app/src/main/scala/app.config.scala create mode 100644 project/Dependencies.scala diff --git a/build.sbt b/build.sbt index 571d4a80..d51b5185 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,6 @@ import org.typelevel.scalacoptions.ScalacOption import org.typelevel.scalacoptions.ScalacOptions +import Dependencies.* lazy val scala213 = "2.13.14" lazy val scala3 = "3.4.1" @@ -63,6 +64,26 @@ lazy val api = (project in file("modules/api")) ) ) +lazy val app = (project in file("modules/app")) + .enablePlugins(Smithy4sCodegenPlugin) + .settings( + name := "lila-search", + commonSettings, + libraryDependencies ++= Seq( + "com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value, + "com.disneystreaming.smithy4s" %% "smithy4s-http4s-swagger" % smithy4sVersion.value, + http4sServer, + http4sEmberClient, + cirisCore, + cirisHtt4s, + logbackX + ), + Compile / run / fork := true, + ) + .enablePlugins(JavaAppPackaging) + .dependsOn(api, core) + lazy val root = project .in(file(".")) - .aggregate(core, play, api) + .settings(publish := {}, publish / skip := true) + .aggregate(core, play, api, app) diff --git a/modules/app/src/main/scala/app.config.scala b/modules/app/src/main/scala/app.config.scala new file mode 100644 index 00000000..21f2f20b --- /dev/null +++ b/modules/app/src/main/scala/app.config.scala @@ -0,0 +1,41 @@ +package lila.search +package app + +import cats.effect.IO +import cats.syntax.all._ +import ciris._ +import ciris.http4s._ +import com.comcast.ip4s._ + +object AppConfig { + + def load: IO[AppConfig] = appConfig.load[IO] + + def appConfig = ( + HttpServerConfig.config, + ElasticConfig.config + ).parMapN(AppConfig.apply) + +} + +case class AppConfig( + server: HttpServerConfig, + elastic: ElasticConfig +) + +case class HttpServerConfig(host: Host, port: Port, shutdownTimeout: Int) + +object HttpServerConfig { + private def host = env("HTTP_HOST").or(prop("http.host")).as[Host].default(ip"0.0.0.0") + private def port = env("HTTP_PORT").or(prop("http.port")).as[Port].default(port"9669") + private def shutdownTimeout = + env("HTTP_SHUTDOWN_TIMEOUT").or(prop("http.shutdown.timeout")).as[Int].default(30) + def config = (host, port, shutdownTimeout).parMapN(HttpServerConfig.apply) +} + +case class ElasticConfig(uri: String) + +object ElasticConfig { + private def uri = env("ELASTIC_URI").or(prop("elastic.uri")).as[String] + def config = uri.map(ElasticConfig.apply) +} diff --git a/project/Dependencies.scala b/project/Dependencies.scala new file mode 100644 index 00000000..f9ee767c --- /dev/null +++ b/project/Dependencies.scala @@ -0,0 +1,41 @@ +import sbt.* + +object Dependencies { + + object V { + val catsEffect = "3.5.4" + val ciris = "3.5.0" + val fs2 = "3.10.2" + val http4s = "0.23.27" + val iron = "2.5.0" + } + + def http4s(artifact: String) = "org.http4s" %% s"http4s-$artifact" % V.http4s + + val catsCore = "org.typelevel" %% "cats-core" % "2.10.0" + val catsEffect = "org.typelevel" %% "cats-effect" % V.catsEffect + + val fs2 = "co.fs2" %% "fs2-core" % V.fs2 + val fs2IO = "co.fs2" %% "fs2-io" % V.fs2 + + val cirisCore = "is.cir" %% "ciris" % V.ciris + val cirisHtt4s = "is.cir" %% "ciris-http4s" % V.ciris + val iron = "io.github.iltotore" %% "iron" % V.iron + val ironCiris = "io.github.iltotore" %% "iron-ciris" % V.iron + + val http4sServer = http4s("ember-server") + val http4sClient = http4s("client") + val http4sEmberClient = http4s("ember-client") + + val log4Cats = "org.typelevel" %% "log4cats-slf4j" % "2.7.0" + val logbackX = "ch.qos.logback" % "logback-classic" % "1.5.6" + + val ducktape = "io.github.arainko" %% "ducktape" % "0.2.0" + + + val testContainers = "com.dimafeng" %% "testcontainers-scala-postgresql" % "0.41.3" % Test + val weaver = "com.disneystreaming" %% "weaver-cats" % "0.8.4" % Test + val weaverScalaCheck = "com.disneystreaming" %% "weaver-scalacheck" % "0.8.4" % Test + val catsEffectTestKit = "org.typelevel" %% "cats-effect-testkit" % V.catsEffect % Test + val scalacheck = "org.scalacheck" %% "scalacheck" % "1.17.0" % Test +}