1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 18:09:22 +02:00

handle application prefix for handlers; use handler for StaticFiles

This commit is contained in:
Nikolay Kim
2018-01-02 15:23:31 -08:00
parent 77ba1de305
commit f0fdcc9936
4 changed files with 64 additions and 19 deletions

View File

@ -25,9 +25,8 @@ fn main() {
## Directory
To serve files from specific directory and sub-directories `StaticFiles` could be used.
`StaticFiles` could be registered with `Application::resource` method.
`StaticFiles` requires tail named path expression for resource registration.
And this name has to be used in `StaticFile` constructor.
`StaticFiles` must be registered with `Application::handler()` method otherwise
it won't be able to server sub-paths.
```rust
# extern crate actix_web;
@ -35,12 +34,11 @@ use actix_web::*;
fn main() {
Application::new()
.resource("/static/{tail:.*}", |r| r.h(fs::StaticFiles::new("tail", ".", true)))
.handler("/static", fs::StaticFiles::new(".", true))
.finish();
}
```
First parameter is a name of path pattern. Second parameter is a base directory.
Third parameter is *show_index*, if it is set to *true*
First parameter is a base directory. Second parameter is *show_index*, if it is set to *true*
directory listing would be returned for directories, if it is set to *false*
then *404 Not Found* would be returned instead of directory listing.