add sub routes to backend app
in the shape of websocket and post \ get with receiving of some request model
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package industries.sunshine.planningpoker
|
||||
|
||||
import cats.effect._
|
||||
import cats.syntax.all._
|
||||
import org.http4s._, org.http4s.dsl.io._, org.http4s.implicits._
|
||||
import com.comcast.ip4s._
|
||||
import org.http4s.HttpRoutes
|
||||
import org.http4s.dsl.io._
|
||||
import org.http4s.implicits._
|
||||
import org.http4s.ember.server._
|
||||
|
||||
object App extends IOApp.Simple {
|
||||
|
||||
val service = HttpRoutes
|
||||
.of[IO] { case _ =>
|
||||
Ok("hello")
|
||||
}
|
||||
.orNotFound
|
||||
|
||||
override def run: IO[Unit] = {
|
||||
val a = 1
|
||||
IO.println(s"Hello, World! $a") >>
|
||||
EmberServerBuilder
|
||||
.default[IO]
|
||||
.withHost(ipv4"0.0.0.0")
|
||||
.withPort(port"8080")
|
||||
.withHttpApp(service)
|
||||
.build
|
||||
.use(_ => IO.never)
|
||||
.as(ExitCode.Success)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package industries.sunshine.planningpoker
|
||||
|
||||
import cats.effect._
|
||||
import cats.syntax.all._
|
||||
import org.http4s._, org.http4s.dsl.io._, org.http4s.implicits._
|
||||
import com.comcast.ip4s._
|
||||
import org.http4s.HttpRoutes
|
||||
import org.http4s.dsl.io._
|
||||
import org.http4s.implicits._
|
||||
import org.http4s.ember.server._
|
||||
import org.http4s.websocket.WebSocketFrame
|
||||
|
||||
import io.circe.generic.auto._
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
import scala.concurrent.duration._
|
||||
import org.http4s.server.websocket.WebSocketBuilder
|
||||
import fs2._
|
||||
|
||||
object BackendApp extends IOApp.Simple {
|
||||
|
||||
def service(wsb: WebSocketBuilder[IO]) = HttpRoutes
|
||||
.of[IO] {
|
||||
case req @ POST -> Root / login => {
|
||||
for {
|
||||
data <- req.as[Requests.LogIn]
|
||||
resp <- Ok(s"got some: ${data}")
|
||||
} yield resp
|
||||
}
|
||||
case GET -> Root / subscribe => {
|
||||
val send: Stream[IO, WebSocketFrame] =
|
||||
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))
|
||||
}
|
||||
wsb.build(send, receive)
|
||||
}
|
||||
case _ => Ok("hello")
|
||||
}
|
||||
.orNotFound
|
||||
|
||||
override def run: IO[Unit] = {
|
||||
val a = 1
|
||||
IO.println(s"Hello, World! $a") >>
|
||||
EmberServerBuilder
|
||||
.default[IO]
|
||||
.withHost(ipv4"0.0.0.0")
|
||||
.withPort(port"8080")
|
||||
.withHttpWebSocketApp(service)
|
||||
.build
|
||||
.use(_ => IO.never)
|
||||
.as(ExitCode.Success)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user