Skip to content

Commit

Permalink
Doc: Update StaticServer example (#1347)
Browse files Browse the repository at this point in the history
* updated StaticServer example to use the new Path syntax and added a minor correction to the implementation.

* Update StaticServer.scala

rolled back change of the port.

* formatting
  • Loading branch information
gciuloaica authored Jul 14, 2022
1 parent a7d5340 commit 64d48a9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions example/src/main/scala/example/StaticServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import zio.ZIOAppDefault
object StaticServer extends ZIOAppDefault {

// A simple app to serve static resource files from a local directory.
val app = Http.collectHttp[Request] { case Method.GET -> "static" /: path =>
val app = Http.collectHttp[Request] { case Method.GET -> "" /: "static" /: path =>
for {
file <- Http.getResourceAsFile(path.encode.tail)
file <- Http.getResourceAsFile(path.encode)
http <-
// Rendering a custom UI to list all the files in the directory
if (file.isDirectory) {

// Accessing the files in the directory
val files = file.listFiles.toList.sortBy(_.getName)
val base = "/static"
val base = "/static/"
val rest = path.dropLast(1)

// Custom UI to list all the files in the directory
Expand Down

0 comments on commit 64d48a9

Please sign in to comment.