[−][src]Struct rocket_contrib::serve::StaticFiles
Custom handler for serving static files.
This handler makes it simple to serve static files from a directory on the
local file system. To use it, construct a StaticFiles
using either
StaticFiles::from()
or StaticFiles::new()
then simply mount
the
handler at a desired path.
Options
The handler's functionality can be customized by passing an Options
to
StaticFiles::new()
.
Example
To serve files from the /static
directory at the /public
path, allowing
index.html
files to be used to respond to requests for a directory (the
default), you might write the following:
use rocket_contrib::serve::StaticFiles; fn main() { rocket::ignite() .mount("/public", StaticFiles::from("/static")) .launch(); }
With this set-up, requests for files at /public/<path..>
will be handled
by returning the contents of /static/<path..>
. Requests for directories
at /public/<directory>
will be handled by returning the contents of
/static/<directory>/index.html
.
If your static files are stored relative to your crate and your project is
managed by Cargo, you should either use a relative path and ensure that your
server is started in the crate's root directory or use the
CARGO_MANIFEST_DIR
to create an absolute path relative to your crate root.
For example, to serve files in the static
subdirectory of your crate at
/
, you might write:
use rocket_contrib::serve::StaticFiles; fn main() { rocket::ignite() .mount("/", StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/static"))) .launch(); }
Methods
impl StaticFiles
[src]
pub fn from<P: AsRef<Path>>(path: P) -> Self
[src]
Constructs a new StaticFiles
that serves files from the file system
path
. By default, Options::Index
is enabled. To serve static files
with other options, use StaticFiles::new()
.
Example
Serve the static files in the /www/public
local directory on path
/static
.
use rocket_contrib::serve::StaticFiles; fn main() { rocket::ignite() .mount("/static", StaticFiles::from("/www/public")) .launch(); }
pub fn new<P: AsRef<Path>>(path: P, options: Options) -> Self
[src]
Constructs a new StaticFiles
that serves files from the file system
path
with options
enabled.
Example
Serve the static files in the /www/public
local directory on path
/static
without serving index files or dot files. Additionally, serve
the same files on /pub
while also seriving index files and dot files.
use rocket_contrib::serve::{StaticFiles, Options}; fn main() { let options = Options::Index | Options::DotFiles; rocket::ignite() .mount("/static", StaticFiles::from("/www/public")) .mount("/pub", StaticFiles::new("/www/public", options)) .launch(); }
Trait Implementations
impl Clone for StaticFiles
[src]
fn clone(&self) -> StaticFiles
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Into<Vec<Route>> for StaticFiles
[src]
impl Handler for StaticFiles
[src]
Auto Trait Implementations
impl Send for StaticFiles
impl Sync for StaticFiles
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Typeable for T where
T: Any,
T: Any,
impl<F> Handler for F where
F: 'static + Send + Sync + Clone + for<'r> Fn(&'r Request, Data) -> Outcome<Response<'r>, Status, Data>,
[src]
F: 'static + Send + Sync + Clone + for<'r> Fn(&'r Request, Data) -> Outcome<Response<'r>, Status, Data>,
impl<T> Cloneable for T where
T: Handler + Clone,
[src]
T: Handler + Clone,
fn clone_handler(&self) -> Box<dyn Handler + 'static>
[src]
impl<T> IntoCollection for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
impl<T, I> AsResult for T where
I: Input,
I: Input,
impl<T> IntoSql for T
[src]
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]
Self: AsExpression<T>,
Convert self
to an expression for Diesel's query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
[src]
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel's query builder. Read more
impl<T> Same for T
type Output = T
Should always be Self
impl<T> Erased for T
impl<T, U> TryInto for T where
U: TryFrom<T>,
U: TryFrom<T>,