Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve docs #2482

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading