feat(server): Http4s server
Build & Test (NowChessSystems) TeamCity build failed

Changed at how the run command starts TUI GUI and the server. This is neccessary so that TUI GUI and server start and the game from the TUI/GUI is registered in the server.
This commit is contained in:
LQ63
2026-04-12 18:50:47 +02:00
parent 25c113e4d5
commit df675a5f08
4 changed files with 34 additions and 3 deletions
+4
View File
@@ -40,3 +40,7 @@ val versions = mapOf(
)
extra["VERSIONS"] = versions
tasks.register("run") {
dependsOn(":modules:ui:run")
}
@@ -0,0 +1,25 @@
package de.nowchess.server
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import com.comcast.ip4s.{host, port}
import de.nowchess.api.player.{PlayerId, PlayerInfo}
import de.nowchess.chess.engine.GameEngine
import org.http4s.ember.server.EmberServerBuilder
object ServerLauncher:
def start(engine: GameEngine): String =
val white = PlayerInfo(PlayerId("white"), "Player 1")
val black = PlayerInfo(PlayerId("black"), "Player 2")
(for
registry <- GameRegistry.make
_ <- EmberServerBuilder
.default[IO]
.withHost(host"0.0.0.0")
.withPort(port"8080")
.withHttpApp(BoardRoutes(registry).routes.orNotFound)
.build
.useForever
.start
gameId <- registry.add(GameEntry(engine, white, black))
yield gameId).unsafeRunSync()
+1
View File
@@ -64,6 +64,7 @@ dependencies {
implementation(project(":modules:rule"))
implementation(project(":modules:api"))
implementation(project(":modules:io"))
implementation(project(":modules:server"))
// ScalaFX dependencies
implementation("org.scalafx:scalafx_3:${versions["SCALAFX"]!!}")
@@ -1,21 +1,22 @@
package de.nowchess.ui
import de.nowchess.chess.engine.GameEngine
import de.nowchess.server.ServerLauncher
import de.nowchess.ui.terminal.TerminalUI
import de.nowchess.ui.gui.ChessGUILauncher
/** Application entry point - starts both GUI and Terminal UI for the chess game.
* Both views subscribe to the same GameEngine via Observer pattern.
* The REST server shares the same engine instance, so API moves are reflected in the UI.
*/
object Main:
def main(args: Array[String]): Unit =
// Create the core game engine (single source of truth)
val engine = new GameEngine()
val gameId = ServerLauncher.start(engine)
println(s"REST API ready — game ID: $gameId → http://localhost:8080/api/board/game/$gameId")
// Launch ScalaFX GUI in separate thread
ChessGUILauncher.launch(engine)
// Create and start the terminal UI (blocks on main thread)
val tui = new TerminalUI(engine)
tui.start()