Function aitch::handlers::static_files::static_files_handler[][src]

pub fn static_files_handler<P>(
    root_path: P
) -> Result<impl Handler<()>> where
    P: AsRef<Path> + Clone + Send + Sync + 'static, 

Serves files from a directory, based on the path of incoming HTTP requests.

A request of GET /path/to/file.html will be translated to root_dir/path/to/file.html, and the resulting file returned in the response.

Any errors that occur while reading the file from disk (including file not found) result in an empty HTTP 404 response.

See the module level documentation for details of the MIME types used to serve responses.

Errors

This function checks the directory exists when called, and attempts to canoncicalize the path. If this fails for any reason (such as directory not found), it returns an error.

Security

This handler is intended for development use only. See the module level documentation for more details.