-
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.
Add docs for serving static files (#2554)
* add docs for serving static files * fmt
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 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
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) | ||
} | ||
|
||
``` |
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,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) | ||
} |