Struct actix_web_static_files::ResourceFiles
source · pub struct ResourceFiles { /* 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 ResourceFiles
impl ResourceFiles
pub fn new(path: &str, files: HashMap<&'static str, Resource>) -> 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 an actix_web::guard::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 Deref for ResourceFiles
impl Deref for ResourceFiles
source§impl HttpServiceFactory for ResourceFiles
impl HttpServiceFactory for ResourceFiles
fn register(self, config: &mut AppService)
source§impl ServiceFactory<ServiceRequest> for ResourceFiles
impl ServiceFactory<ServiceRequest> for ResourceFiles
§type Response = ServiceResponse<BoxBody>
type Response = ServiceResponse<BoxBody>
§type Future = Pin<Box<dyn Future<Output = Result<<ResourceFiles as ServiceFactory<ServiceRequest>>::Service, <ResourceFiles as ServiceFactory<ServiceRequest>>::InitError>> + 'static, Global>>
type Future = Pin<Box<dyn Future<Output = Result<<ResourceFiles as ServiceFactory<ServiceRequest>>::Service, <ResourceFiles as ServiceFactory<ServiceRequest>>::InitError>> + 'static, Global>>
Service
instance.gsource§fn new_service(&self, _: ()) -> Self::Future
fn new_service(&self, _: ()) -> Self::Future
Auto Trait Implementations§
impl RefUnwindSafe for ResourceFiles
impl !Send for ResourceFiles
impl !Sync for ResourceFiles
impl Unpin for ResourceFiles
impl UnwindSafe for ResourceFiles
Blanket Implementations§
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>
§impl<SF, Req> IntoServiceFactory<SF, Req> for SFwhere
SF: ServiceFactory<Req>,
impl<SF, Req> IntoServiceFactory<SF, Req> for SFwhere SF: ServiceFactory<Req>,
§fn into_factory(self) -> SF
fn into_factory(self) -> SF
Self
to a ServiceFactory