WIP: feat: NCS-38 Http4s server #26

Closed
lq64 wants to merge 2 commits from feat/NCS-38 into main
4 changed files with 34 additions and 3 deletions
Showing only changes of commit df675a5f08 - Show all commits
+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()