Function warp::filters::fs::file [−][src]
pub fn file(
path: impl Into<PathBuf>
) -> impl FilterClone<Extract = (File,), Error = Rejection>
Creates a Filter
that serves a File at the path
.
Does not filter out based on any information of the request. Always serves
the file at the exact path
provided. Thus, this can be used to serve a
single file with GET
s, but could also be used in combination with other
filters, such as after validating in POST
request, wanting to return a
specific file as the body.
For serving a directory, see dir.
Example
// Always serves this file from the file system. let route = warp::fs::file("/www/static/app.js");
Note
This filter uses tokio-fs
to serve files, which requires the server
to be run in the threadpool runtime. This is only important to remember
if starting a runtime manually.