Skip to content

Commit

Permalink
Merge branch 'zio:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayhul-Jindal authored Oct 15, 2023
2 parents d7694c4 + 3a6525c commit 41317a2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion zio-http/src/main/scala/zio/http/Middleware.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,28 @@ object Middleware extends HandlerAspects {

/**
* Creates a middleware for serving static files from the directory `docRoot`
* at the path `path`.
* at the url path `path`.
*
* Example: `val serveDirectory = Middleware.serveDirectory(Path.empty /
* "assets", new File("/some/local/path"))`
*
* With this middleware in place, a request to
* `https://www.domain.com/assets/folder/file1.jpg` would serve the local file
* `/some/local/path/folder/file1.jpg`.
*/
def serveDirectory(path: Path, docRoot: File)(implicit trace: Trace): Middleware[Any] =
toMiddleware(path, StaticServe.fromDirectory(docRoot))

/**
* Creates a middleware for serving static files from resources at the path
* `path`.
*
* Example: `val serveResources = Middleware.serveResources(Path.empty /
* "assets")`
*
* With this middleware in place, a request to
* `https://www.domain.com/assets/folder/file1.jpg` would serve the file
* `src/main/resources/folder/file1.jpg`.
*/
def serveResources(path: Path)(implicit trace: Trace): Middleware[Any] =
toMiddleware(path, StaticServe.fromResource)
Expand Down

0 comments on commit 41317a2

Please sign in to comment.