Skip to content

Commit

Permalink
feat: fix mongo config when no port & support gzip (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio <Pinheiro>
  • Loading branch information
FabioPinheiro authored and Fabio committed Apr 30, 2024
1 parent e03d815 commit 17937c0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ lazy val mediator = project
* all tasks for production, including Scala.js fullOptJS task and source maps scalaJSDev task runs all tasks for
* development, including Scala.js fastOptJS task and source maps.
*/
Assets / pipelineStages := Seq(scalaJSPipeline),
Assets / pipelineStages := Seq(scalaJSPipeline, gzip),
// pipelineStages ++= Seq(digest, gzip), //Compression - If you serve your Scala.js application from a web server, you should additionally gzip the resulting .js files.
Compile / unmanagedResourceDirectories += baseDirectory.value / "src" / "main" / "extra-resources",
// Compile / unmanagedResourceDirectories += (baseDirectory.value.toPath.getParent.getParent / "docs-build" / "target" / "mdoc").toFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ object MediatorAgent {

def didCommApp = {
Http.collectZIO[Request] {
case req @ Method.GET -> !! / "headers" =>
val data = req.headersAsList.toSeq.map(e => (e.key.toString(), e.value.toString()))
ZIO.succeed(Response.text("HEADERS:\n" + data.mkString("\n") + "\nRemoteAddress:" + req.remoteAddress)).debug
case req @ Method.GET -> !! / "health" => ZIO.succeed(Response.ok)

case req @ Method.GET -> !! if req.headersAsList.exists { h =>
h.key.toString.toLowerCase == "content-type" &&
(h.value.toString.startsWith(MediaTypes.SIGNED.typ) ||
Expand Down Expand Up @@ -273,19 +278,39 @@ object MediatorAgent {
Request,
Response
]
} ++ Http.fromResource(s"public/webapp-fastopt-library.js").when {
case Method.GET -> !! / "public" / "webapp-fastopt-library.js" => true
case _ => false
} ++ {
Http.fromResource(s"public/webapp-fastopt-bundle.js").when {
case Method.GET -> !! / "public" / path => true
// Response(
// body = Body.fromStream(ZStream.fromIterator(Source.fromResource(s"public/$path").iter).map(_.toByte)),
// headers = Headers(HeaderNames.contentType, HeaderValues.applicationJson),
// )
case _ => false
} /* ++ Http.fromResource(s"public/webapp-fastopt-bundle.js.gz").when {
case Method.GET -> !! / "public" / "webapp-fastopt-bundle.js.gz" => true
case _ => false
} */ ++ Http
.fromResource(s"public/webapp-fastopt-bundle.js.gz")
.map(e =>
e.setHeaders(
Headers(
e.headers.filter(_.key != "content-encoding") ++ Seq(
Header("content-type", "application/javascript"),
Header("content-encoding", "gzip"),
)
)
)
)
.when {
case Method.GET -> !! / "public" / "webapp-fastopt-bundle.js" => true
case _ => false
}
} @@
// ++ {
// Http
// .fromResource(s"public/webapp-fastopt-bundle.js")
// // .map(e => e.addHeader())
// .when {
// case Method.GET -> !! / "public" / path => true
// // Response(
// // body = Body.fromStream(ZStream.fromIterator(Source.fromResource(s"public/$path").iter).map(_.toByte)),
// // headers = Headers(HeaderNames.contentType, HeaderValues.applicationJson),
// // )
// case _ => false
// }
// }
@@
HttpAppMiddleware.cors(
zio.http.middleware.Cors.CorsConfig(
allowedOrigins = _ => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ case class MediatorConfig(endpoint: java.net.URI, keyAgreement: OKPPrivateKey, k
case class DataBaseConfig(
protocol: String,
host: String,
port: String,
port: Option[String],
userName: String,
password: String,
dbName: String
) {
val connectionString = s"$protocol://$userName:$password@$host:$port/$dbName"
val displayConnectionString = s"$protocol://$userName:******@$host:$port/$dbName"
private def maybePort = port.filter(_.nonEmpty).map(":" + _).getOrElse("")
val connectionString = s"$protocol://$userName:$password@$host$maybePort/$dbName"
val displayConnectionString = s"$protocol://$userName:******@$host$maybePort/$dbName"
override def toString: String = s"""DataBaseConfig($protocol, $host, $port, $userName, "******", $dbName)"""
}

Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")

// Deploy demo
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.2")

// Release
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
Expand Down

0 comments on commit 17937c0

Please sign in to comment.