Skip to content

Commit

Permalink
Merge pull request metosin#476 from metosin/feature/update-static-han…
Browse files Browse the repository at this point in the history
…dler-docs

Document serving static resources from the file system
  • Loading branch information
Miikka Koskinen authored Apr 9, 2021
2 parents b8110f1 + d0e83fe commit ac9ff80
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions doc/ring/static.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Static Resources (Clojure Only)

Static resources can be served using `reitit.ring/create-resource-handler`. It takes optionally an options map and returns a ring handler to serve files from Classpath.
Static resources can be served by using the following two functions:

There are two options to serve the files.
* `reitit.ring/create-resource-handler`, which returns a Ring handler that serves files from classpath, and
* `reitit.ring/create-file-handler`, which returns a Ring handler that servers files from file system

There are two ways to mount the handlers.
The examples below use `reitit.ring/create-resource-handler`, but `reitit.ring/create-file-handler` works the same way.

## Internal routes

Expand Down Expand Up @@ -33,7 +37,9 @@ To serve static files with conflicting routes, e.g. `"/*"`, one needs to disable

## External routes

A better way to serve files from conflicting paths, e.g. `"/*"`, is to serve them from the default-handler. One can compose multiple default locations using `ring-handler`. This way, they are only served if none of the actual routes have matched.
A better way to serve files from conflicting paths, e.g. `"/*"`, is to serve them from the default-handler.
One can compose multiple default locations using `reitit.ring/ring-handler`.
This way, they are only served if none of the actual routes have matched.

```clj
(ring/ring-handler
Expand All @@ -46,10 +52,10 @@ A better way to serve files from conflicting paths, e.g. `"/*"`, is to serve the

## Configuration

`reitit.ring/create-resource-handler` takes optionally an options map to configure how the files are being served.
`reitit.ring/create-file-handler` and `reitit.ring/create-resource-handler` take optionally an options map to configure how the files are being served.

| key | description |
| -----------------|-------------|
| key | description |
| -------------------|-------------|
| :parameter | optional name of the wildcard parameter, defaults to unnamed keyword `:`
| :root | optional resource root, defaults to `\"public\"`
| :path | path to mount the handler to. Required when mounted outside of a router, does not work inside a router.
Expand All @@ -58,9 +64,7 @@ A better way to serve files from conflicting paths, e.g. `"/*"`, is to serve the
| :not-found-handler | optional handler function to use if the requested resource is missing (404 Not Found)



### TODO

* support for things like `:cache`, `:etag`, `:last-modified?`, and `:gzip`
* support for ClojureScript
* serve from file-system

0 comments on commit ac9ff80

Please sign in to comment.