-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rishi Raj Jain
committed
Nov 23, 2023
1 parent
2f8a343
commit ddf6f92
Showing
14 changed files
with
66 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
zio-http-react-example/src/main/scala/react_example/ReactHelloWorld.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package react_example | ||
|
||
import zio._ | ||
import zio.http._ | ||
import zio.stream.ZStream | ||
|
||
import java.io.File | ||
import java.nio.file.Paths | ||
|
||
object ReactHelloWorld extends ZIOAppDefault { | ||
// Create the build relative directory path | ||
private val buildDirectory = "src/main/scala/react_example/react/build" | ||
|
||
val app: HttpApp[Any] = Routes.singleton { | ||
handler { (_: Path, req: Request) => { | ||
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)) | ||
} | ||
} | ||
} | ||
}.toHttpApp | ||
|
||
// Run it like any simple app | ||
val run = Server.serve(app).provide(Server.default) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.