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

Add docs for serving static files #2554

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
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
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)
}
Loading