-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
615785c
commit 3e12680
Showing
8 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Redis | ||
REDIS_HOST=localhost | ||
REDIS_PORT=5432 | ||
|
||
# http server | ||
HTTP_SERVER_HOST=0.0.0.0 | ||
HTTP_SERVER_PORT=9665 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<configuration> | ||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>logs/application.log</file> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
<appender-ref ref="FILE"/> | ||
</root> | ||
|
||
<logger name="http4s"/> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package lila.fishnet | ||
|
||
import cats.effect.{ IO, IOApp } | ||
import cats.effect.* | ||
import org.typelevel.log4cats.Logger | ||
import org.typelevel.log4cats.slf4j.Slf4jLogger | ||
|
||
import lila.fishnet.http.* | ||
|
||
object App extends IOApp.Simple: | ||
|
||
given Logger[IO] = Slf4jLogger.getLogger[IO] | ||
|
||
given client: LilaClient = new LilaClient: | ||
def send(move: Lila.Move): IO[Unit] = | ||
IO.println(s"send $move") | ||
|
||
override def run: IO[Unit] = Config | ||
.load | ||
.flatMap: cfg => | ||
Executor.apply.flatMap: ec => | ||
val app = HttpApi(ec, HealthCheck()).httpApp | ||
MkHttpServer.apply.newEmber(cfg.server, app) | ||
.useForever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package lila.fishnet | ||
|
||
import org.http4s.* | ||
import cats.effect.{ IO, Resource } | ||
import fs2.io.net.Network | ||
import org.http4s.ember.server.EmberServerBuilder | ||
import org.http4s.server.Server | ||
import org.http4s.server.defaults.Banner | ||
import org.typelevel.log4cats.Logger | ||
|
||
trait MkHttpServer: | ||
def newEmber(cfg: HttpServerConfig, httpApp: HttpApp[IO]): Resource[IO, Server] | ||
|
||
object MkHttpServer: | ||
|
||
def apply(using server: MkHttpServer): MkHttpServer = server | ||
|
||
given forAsyncLogger(using Logger[IO]): MkHttpServer = new: | ||
|
||
def newEmber(cfg: HttpServerConfig, httpApp: HttpApp[IO]): Resource[IO, Server] = EmberServerBuilder | ||
.default[IO] | ||
.withHost(cfg.host) | ||
.withPort(cfg.port) | ||
.withHttpApp(httpApp) | ||
.build | ||
.evalTap(showEmberBanner) | ||
|
||
private def showEmberBanner(s: Server): IO[Unit] = | ||
Logger[IO].info(s"\n${Banner.mkString("\n")}\nHTTP Server started at ${s.address}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters