diff --git a/actix-files/CHANGES.md b/actix-files/CHANGES.md index 978d1c69d..c4d56010f 100644 --- a/actix-files/CHANGES.md +++ b/actix-files/CHANGES.md @@ -3,6 +3,10 @@ ## Unreleased - 2020-xx-xx +## 0.4.1 - 2020-11-24 +* Clarify order of parameters in `Files::new` and improve docs. + + ## 0.4.0 - 2020-10-06 * Add `Files::prefer_utf8` option that adds UTF-8 charset on certain response types. [#1714] diff --git a/actix-files/src/files.rs b/actix-files/src/files.rs index 5a783e2dd..a99b4699e 100644 --- a/actix-files/src/files.rs +++ b/actix-files/src/files.rs @@ -65,13 +65,25 @@ impl Clone for Files { } impl Files { - /// Create new `Files` instance for specified base directory. + /// Create new `Files` instance for a specified base directory. /// - /// `File` uses `ThreadPool` for blocking filesystem operations. - /// By default pool with 5x threads of available cpus is used. - /// Pool size can be changed by setting ACTIX_THREADPOOL environment variable. - pub fn new>(path: &str, dir: T) -> Files { - let orig_dir = dir.into(); + /// # Argument Order + /// The first argument (`mount_path`) is the root URL at which the static files are served. + /// For example, `/assets` will serve files at `example.com/assets/...`. + /// + /// The second argument (`serve_from`) is the location on disk at which files are loaded. + /// This can be a relative path. For example, `./` would serve files from the current + /// working directory. + /// + /// # Implementation Notes + /// If the mount path is set as the root path `/`, services registered after this one will + /// be inaccessible. Register more specific handlers and services first. + /// + /// `Files` uses a threadpool for blocking filesystem operations. By default, the pool uses a + /// number of threads equal to 5x the number of available logical CPUs. Pool size can be changed + /// by setting ACTIX_THREADPOOL environment variable. + pub fn new>(mount_path: &str, serve_from: T) -> Files { + let orig_dir = serve_from.into(); let dir = match orig_dir.canonicalize() { Ok(canon_dir) => canon_dir, Err(_) => { @@ -81,7 +93,7 @@ impl Files { }; Files { - path: path.to_string(), + path: mount_path.to_owned(), directory: dir, index: None, show_index: false,