diff options
author | Billy Bradley <billy@squeno.com> | 2021-10-10 13:13:43 +0000 |
---|---|---|
committer | Billy Bradley <billy@squeno.com> | 2021-10-10 13:13:43 +0000 |
commit | 9772505ccb2499a8f533d649b8334fd9bf765631 (patch) | |
tree | 7418c9e2a2b5c7175574fbbb88a7bab41b18a622 /src/main.rs | |
parent | Add --spa-index option (diff) | |
download | miniserve-9772505ccb2499a8f533d649b8334fd9bf765631.tar.gz miniserve-9772505ccb2499a8f533d649b8334fd9bf765631.zip |
Use NamedFile as default handler to simplify --spa-index option implementation
Diffstat (limited to '')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs index f3dc18a..7420888 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use std::path::PathBuf; use std::thread; use std::time::Duration; +use actix_files::NamedFile; use actix_web::web; use actix_web::{http::header::ContentType, Responder}; use actix_web::{middleware, App, HttpRequest, HttpResponse}; @@ -320,23 +321,10 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { None => files, }; let files = match &conf.spa_index { - Some(spa_index_file) => { - let spa_index_full = &conf.path.join(spa_index_file); - let spa_index_string: String = spa_index_full.to_string_lossy().into(); - - files.default_handler(move |req: actix_web::dev::ServiceRequest| { - let (request, _payload) = req.into_parts(); - let spa_index_string = spa_index_string.clone(); - - async move { - let response = actix_files::NamedFile::open( - &spa_index_string - )? - .into_response(&request); - Ok(actix_web::dev::ServiceResponse::new(request, response)) - } - }) - }, + Some(spa_index_file) => files.default_handler( + NamedFile::open(&conf.path.join(spa_index_file)) + .expect("Cant open SPA index file.") + ), None => files.default_handler(web::to(error_404)), }; let files = match conf.show_hidden { |