Skip to content

Commit

Permalink
Add docs for serving static files (#2554)
Browse files Browse the repository at this point in the history
* add docs for serving static files

* fmt
  • Loading branch information
zalbia authored Dec 12, 2023
1 parent f9ffb0b commit 9a9aef2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/examples/advanced/static-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: static-files
title: "Serving Static Files"
sidebar_label: "Static Files"
---

```scala mdoc:silent
import zio._
import zio.http._

object StaticFiles extends ZIOAppDefault {

/**
* Creates an HTTP app that only serves static files from resources via
* "/static". For paths other than the resources directory, see
* [[Middleware.serveDirectory]].
*/
val app = Routes.empty.toHttpApp @@ Middleware.serveResources(Path.empty / "static")

override def run = Server.serve(app).provide(Server.default)
}

```
17 changes: 17 additions & 0 deletions zio-http-example/src/main/scala/example/StaticFiles.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package example

import zio._

import zio.http._

object StaticFiles extends ZIOAppDefault {

/**
* Creates an HTTP app that only serves static files from resources via
* "/static". For paths other than the resources directory, see
* [[Middleware.serveDirectory]].
*/
val app = Routes.empty.toHttpApp @@ Middleware.serveResources(Path.empty / "static")

override def run = Server.serve(app).provide(Server.default)
}

0 comments on commit 9a9aef2

Please sign in to comment.