From dd4ec9efdc5eb17cebb72905e06c76e152c1a11f Mon Sep 17 00:00:00 2001 From: Rishi Raj Jain Date: Thu, 23 Nov 2023 21:35:58 +0530 Subject: [PATCH] if/else --- .../advanced/fullstack-with-react-apps.md | 22 ++++++++++--------- project/Dependencies.scala | 1 + .../scala/react_example/ReactHelloWorld.scala | 22 ++++++++++--------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/docs/examples/advanced/fullstack-with-react-apps.md b/docs/examples/advanced/fullstack-with-react-apps.md index 5cc6b67d5e..1e07064ace 100644 --- a/docs/examples/advanced/fullstack-with-react-apps.md +++ b/docs/examples/advanced/fullstack-with-react-apps.md @@ -21,21 +21,23 @@ object ReactHelloWorld extends ZIOAppDefault { if (req.url.path.toString == "/api/hello") { Response.text("Hello World") } - if (req.url.path.toString == "/") { - val file = new File(s"$buildDirectory/index.html") - val length = Headers(Header.ContentLength(file.length())) - Response(headers = length, body = Body.fromFile(file)) - } else { - val tmp = req.url.path.toString - val file = new File(s"$buildDirectory/$tmp") - val length = Headers(Header.ContentLength(file.length())) - Response(headers = length, body = Body.fromFile(file)) + if (req.url.path.toString == "/") { + val file = new File(s"$buildDirectory/index.html") + val length = Headers(Header.ContentLength(file.length())) + Response(headers = length, body = Body.fromFile(file)) + } + else { + val tmp = req.url.path.toString + val file = new File(s"$buildDirectory/$tmp") + val length = Headers(Header.ContentLength(file.length())) + Response(headers = length, body = Body.fromFile(file)) + } } } } }.toHttpApp - + // Run it like any simple app val run = Server.serve(app).provide(Server.default) } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 2021be2583..b294f6a55a 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -31,6 +31,7 @@ object Dependencies { val zio = "dev.zio" %% "zio" % ZioVersion val `zio-cli` = "dev.zio" %% "zio-cli" % ZioCliVersion + val `zio-http` = "dev.zio" %% "zio-http" % ZioVersion val `zio-streams` = "dev.zio" %% "zio-streams" % ZioVersion val `zio-schema` = "dev.zio" %% "zio-schema" % ZioSchemaVersion val `zio-schema-json` = "dev.zio" %% "zio-schema-json" % ZioSchemaVersion diff --git a/zio-http-react-example/src/main/scala/react_example/ReactHelloWorld.scala b/zio-http-react-example/src/main/scala/react_example/ReactHelloWorld.scala index 03ec0e885b..ea2397ce7a 100644 --- a/zio-http-react-example/src/main/scala/react_example/ReactHelloWorld.scala +++ b/zio-http-react-example/src/main/scala/react_example/ReactHelloWorld.scala @@ -16,21 +16,23 @@ object ReactHelloWorld extends ZIOAppDefault { if (req.url.path.toString == "/api/hello") { Response.text("Hello World") } - if (req.url.path.toString == "/") { - val file = new File(s"$buildDirectory/index.html") - val length = Headers(Header.ContentLength(file.length())) - Response(headers = length, body = Body.fromFile(file)) - } else { - val tmp = req.url.path.toString - val file = new File(s"$buildDirectory/$tmp") - val length = Headers(Header.ContentLength(file.length())) - Response(headers = length, body = Body.fromFile(file)) + if (req.url.path.toString == "/") { + val file = new File(s"$buildDirectory/index.html") + val length = Headers(Header.ContentLength(file.length())) + Response(headers = length, body = Body.fromFile(file)) + } + else { + val tmp = req.url.path.toString + val file = new File(s"$buildDirectory/$tmp") + val length = Headers(Header.ContentLength(file.length())) + Response(headers = length, body = Body.fromFile(file)) + } } } } }.toHttpApp - + // Run it like any simple app val run = Server.serve(app).provide(Server.default) }