1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 08:22:59 +01:00

Guide: updates to static file handling chapter.

This commit is contained in:
memoryruins 2018-04-06 18:40:57 -04:00
parent a88e97edba
commit c3fbba2678

View File

@ -2,8 +2,8 @@
## Individual file ## Individual file
It is possible to serve static files with custom path pattern and `NamedFile`. To It is possible to serve static files with a custom path pattern and `NamedFile`. To
match path tail we can use `[.*]` regex. match a path tail, we can use a `[.*]` regex.
```rust ```rust
# extern crate actix_web; # extern crate actix_web;
@ -24,9 +24,9 @@ fn main() {
## Directory ## Directory
To serve files from specific directory and sub-directories `StaticFiles` could be used. To serve files from specific directories and sub-directories, `StaticFiles` can be used.
`StaticFiles` must be registered with `App::handler()` method otherwise `StaticFiles` must be registered with an `App::handler()` method, otherwise
it won't be able to serve sub-paths. it will be unable to serve sub-paths.
```rust ```rust
# extern crate actix_web; # extern crate actix_web;
@ -39,11 +39,11 @@ fn main() {
} }
``` ```
First parameter is a base directory. Second parameter is *show_index*, if it is set to *true* The first parameter is the base directory. If the second parameter, *show_index*, is set to **true**,
directory listing would be returned for directories, if it is set to *false* the directory listing will be returned, and if it is set to **false**,
then *404 Not Found* would be returned instead of directory listing. *404 Not Found* will be returned.
Instead of showing files listing for directory, it is possible to redirect to specific Instead of showing files listing for directory, it is possible to redirect to a specific
index file. Use index file. Use the
[*StaticFiles::index_file()*](../actix_web/s/struct.StaticFiles.html#method.index_file) [*StaticFiles::index_file()*](../actix_web/s/struct.StaticFiles.html#method.index_file)
method to configure this redirect. method to configure this redirect.