pub struct ResourceFiles<C = HashMap<&'static str, Resource>> { /* private fields */ }
Expand description
Static resource files handling
ResourceFiles
service must be registered with App::service
method.
use std::collections::HashMap;
use actix_web::App;
fn main() {
// serve root directory with default options:
// - resolve index.html
let files: HashMap<&'static str, static_files::Resource> = HashMap::new();
let app = App::new()
.service(actix_web_static_files::ResourceFiles::new("/", files));
// or subpath with additional option to not resolve index.html
let files: HashMap<&'static str, static_files::Resource> = HashMap::new();
let app = App::new()
.service(actix_web_static_files::ResourceFiles::new("/imgs", files)
.do_not_resolve_defaults());
}
Implementations§
Source§impl<F> ResourceFiles<F>where
F: ResourceFilesCollection + 'static,
impl<F> ResourceFiles<F>where
F: ResourceFilesCollection + 'static,
pub fn new(path: &str, files: F) -> Self
Sourcepub fn do_not_resolve_defaults(self) -> Self
pub fn do_not_resolve_defaults(self) -> Self
By default trying to resolve ‘…/’ to ‘…/index.html’ if it exists. Turn off this resolution by calling this function.
Sourcepub fn resolve_not_found_to<S: ToString>(self, path: S) -> Self
pub fn resolve_not_found_to<S: ToString>(self, path: S) -> Self
Resolves not found references to this path.
This can be useful for angular-like applications.
Sourcepub fn resolve_not_found_to_root(self) -> Self
pub fn resolve_not_found_to_root(self) -> Self
Resolves not found references to root path.
This can be useful for angular-like applications.
Sourcepub fn skip_handler_when_not_found(self) -> Self
pub fn skip_handler_when_not_found(self) -> Self
If this is called, we will use a Guard
to check if this request should be handled.
If set to true, we skip using the handler for files that haven’t been found, instead of sending 404s.
Would be ignored, if resolve_not_found_to
or resolve_not_found_to_root
is used.
Can be useful if you want to share files on a (sub)path that’s also used by a different route handler.
Trait Implementations§
Source§impl<C> Deref for ResourceFiles<C>
impl<C> Deref for ResourceFiles<C>
Source§impl<C> HttpServiceFactory for ResourceFiles<C>where
C: ResourceFilesCollection + 'static,
impl<C> HttpServiceFactory for ResourceFiles<C>where
C: ResourceFilesCollection + 'static,
fn register(self, config: &mut AppService)
Source§impl<C> ServiceFactory<ServiceRequest> for ResourceFiles<C>where
C: ResourceFilesCollection + 'static,
impl<C> ServiceFactory<ServiceRequest> for ResourceFiles<C>where
C: ResourceFilesCollection + 'static,
Source§type Response = ServiceResponse
type Response = ServiceResponse
Source§type Future = Pin<Box<dyn Future<Output = Result<<ResourceFiles<C> as ServiceFactory<ServiceRequest>>::Service, <ResourceFiles<C> as ServiceFactory<ServiceRequest>>::InitError>>>>
type Future = Pin<Box<dyn Future<Output = Result<<ResourceFiles<C> as ServiceFactory<ServiceRequest>>::Service, <ResourceFiles<C> as ServiceFactory<ServiceRequest>>::InitError>>>>
Service
instance.gSource§fn new_service(&self, _: ()) -> Self::Future
fn new_service(&self, _: ()) -> Self::Future
Auto Trait Implementations§
impl<C> Freeze for ResourceFiles<C>
impl<C> RefUnwindSafe for ResourceFiles<C>where
C: RefUnwindSafe,
impl<C = HashMap<&'static str, Resource>> !Send for ResourceFiles<C>
impl<C = HashMap<&'static str, Resource>> !Sync for ResourceFiles<C>
impl<C> Unpin for ResourceFiles<C>
impl<C> UnwindSafe for ResourceFiles<C>where
C: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SF, Req> IntoServiceFactory<SF, Req> for SFwhere
SF: ServiceFactory<Req>,
impl<SF, Req> IntoServiceFactory<SF, Req> for SFwhere
SF: ServiceFactory<Req>,
Source§fn into_factory(self) -> SF
fn into_factory(self) -> SF
Self
to a ServiceFactory