Skip to content

Commit

Permalink
Add app with http4s module
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed May 8, 2024
1 parent 22b0f0f commit 0f1783a
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
23 changes: 22 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
41 changes: 41 additions & 0 deletions modules/app/src/main/scala/app.config.scala
Original file line number Diff line number Diff line change
@@ -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)
}
41 changes: 41 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 0f1783a

Please sign in to comment.