Skip to content

Commit

Permalink
Merge pull request #53 from KacperFKorban/http-config
Browse files Browse the repository at this point in the history
Add possibility to configure the http server
  • Loading branch information
KacperFKorban authored Apr 24, 2024
2 parents 6b96a3b + be33858 commit 3a3f519
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions testcases/src/main/scala/main.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package guinep.compiletest

import com.softwaremill.quicklens.*

def upperCaseText(text: String): String =
text.toUpperCase

Expand Down Expand Up @@ -134,6 +136,7 @@ def printsWeirdGADT1(g: WeirdGADT1[Int]): String = g match
@main
def run: Unit =
guinep.web
.withModifyConfig(_.modify(_.httpServerConfig).using(_.port(6969)))
.apply(
upperCaseText,
add,
Expand Down
6 changes: 4 additions & 2 deletions web/src/main/scala/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def web: GuinepWeb =
* @param requireNonNullableInputs when set, all non-nullable types will correspond to required inputs in the frontend
*/
case class GuinepWebConfig(
requireNonNullableInputs: Boolean = false
requireNonNullableInputs: Boolean = false,
httpServerConfig: zio.http.Server.Config = zio.http.Server.Config.default.port(8090)
)

object GuinepWebConfig:
Expand Down Expand Up @@ -56,7 +57,8 @@ private case class GuinepWeb(config: GuinepWebConfig = GuinepWebConfig.default)
s"""|Duplicate function names found: ${functionsInfosMap.filter(_._2.size > 1).keys.mkString(", ")}
|Ignoring duplicates""".stripMargin
)
println("Starting GUInep web server at http://localhost:8090/")
val prettyAddress = config.httpServerConfig.address.getAddress().getHostAddress().toString() + ":" + config.httpServerConfig.address.getPort()
println(s"Starting GUInep web server at $prettyAddress")
webgen.genWeb(
funs = functionsInfos.distinct.map(fun => fun.name -> fun),
config = config
Expand Down
7 changes: 6 additions & 1 deletion web/src/main/scala/webgen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ private[guinep] object webgen {
).sandbox.toHttpApp

def run =
Server.serve(app).provide(Server.defaultWithPort(8090))
Server
.serve(app)
.provide(
ZLayer.succeed(config.httpServerConfig),
Server.live
)
}
}

0 comments on commit 3a3f519

Please sign in to comment.