From 329dc6e8b2b4218d338bb50b6e8309de77578907 Mon Sep 17 00:00:00 2001 From: efim Date: Sun, 23 Apr 2023 18:33:29 +0400 Subject: [PATCH] initial way to run the server: sbt:backend> assembly java -jar backend/target/scala-3.2.0/backend-assembly-0.1.0-SNAPSHOT.jar --- .../planningpoker/MyHttpService.scala | 19 +++++++------------ build.sbt | 3 ++- flake.nix | 1 + project/plugins.sbt | 1 + 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala b/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala index ee7d1a2..829e9d2 100644 --- a/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala +++ b/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala @@ -22,16 +22,12 @@ object MyHttpService { val authedRoomRoutes: AuthedRoutes[(PlayerID, RoomID), IO] = AuthedRoutes.of { - case GET -> Root / subscribe as (playerId, roomId) => { + case GET -> Root / "subscribe" as (playerId, roomId) => { val send: Stream[IO, WebSocketFrame] = - { - val a = Stream + Stream .emits(TestModels.testChangesList) .covary[IO].metered(5.second).map(state => WebSocketFrame.Text(state.asJson.noSpaces)) - Stream - .awakeEvery[IO](1.seconds) - .map(_ => WebSocketFrame.Text("text")) - } + val receive: Pipe[IO, WebSocketFrame, Unit] = _.evalMap { case WebSocketFrame.Text(text, _) => Sync[IO].delay(println(text)) case other => Sync[IO].delay(println(other)) @@ -40,13 +36,13 @@ object MyHttpService { } case GET -> Root / "vote" / vote as (playerId, roomId) => { // TODO forward these to the service implementation - Ok(s">> got $vote from $playerId in $roomId") + IO(println(s">> got $vote from $playerId in $roomId")) >> Ok() } case GET -> Root / "end-voting" as (playerId, roomId) => { - Ok(s">> got request to end voting from $playerId in $roomId") + IO(println(s">> got request to end voting from $playerId in $roomId")) >> Ok() } case GET -> Root / "new-poll" as (playerId, roomId) => { - Ok(s">> got request to start new voting from $playerId in $roomId") + IO(println(s">> got request to start new voting from $playerId in $roomId")) >> Ok() } } @@ -55,7 +51,7 @@ object MyHttpService { val authenticationRoute = HttpRoutes .of[IO] { - case req @ POST -> Root / login => { + case req @ POST -> Root / "login" => { for { data <- req.as[Requests.LogIn] authResult <- auth.accessRoom( @@ -76,7 +72,6 @@ object MyHttpService { } } yield resp } - case _ => Ok("hello") } (authenticationRoute <+> authMiddleware(authedRoomRoutes)).orNotFound diff --git a/build.sbt b/build.sbt index 808a22f..35d9c09 100644 --- a/build.sbt +++ b/build.sbt @@ -52,7 +52,8 @@ lazy val backend = project // available for 2.12, 2.13, 3.2 libraryDependencies += "co.fs2" %% "fs2-core" % "3.6.1", libraryDependencies += "org.typelevel" %% "cats-core" % "2.9.0", - libraryDependencies += "org.typelevel" %% "cats-effect" % "3.4.9" + libraryDependencies += "org.typelevel" %% "cats-effect" % "3.4.9", + assembly / mainClass := Some("industries.sunshine.planningpoker.BackendApp"), ) .dependsOn(common.jvm) diff --git a/flake.nix b/flake.nix index 1ebda46..8f6bbe4 100644 --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,7 @@ pkgs.nodejs pkgs.sbt pkgs.scalafmt + pkgs.jdk # pkgs.nodePackages.tailwindcss # pkgs.nodePackages.postcss ]; diff --git a/project/plugins.sbt b/project/plugins.sbt index 4611af7..357f8cd 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,2 +1,3 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.1") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1")