Use static directory.
This commit is contained in:
1 parent
eca4820fd2
commit
86598c0fb7
10 files changed
+31
-17
No files matched your search
+6
-1
@@ -11,6 +11,7 @@ use std::path::Path;
|
||||
use std::{collections::HashMap, env, fs, io, path::PathBuf};
|
||||
use tokio::time::{sleep, Duration};
|
||||
use futures::{pin_mut, select, FutureExt};
|
||||
use actix_files;
|
||||
|
||||
|
||||
|
||||
@@ -92,12 +93,16 @@ pub async fn web_ui_main(port: u16, enable_template_autoreload: bool) -> std::io
|
||||
let server = HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(tmpl_reloader.clone())
|
||||
.service(
|
||||
actix_files::Files::new("/static", "./resources/static/")
|
||||
.show_files_listing()
|
||||
.use_last_modified(true),
|
||||
)
|
||||
.service(views::index)
|
||||
.service(views::actions)
|
||||
.service(views::overview)
|
||||
.service(views::overview_submit_button)
|
||||
.service(views::actions_partials)
|
||||
.service(views::static_file)
|
||||
.service(views::push_event)
|
||||
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, not_found))
|
||||
.wrap(Logger::default())
|
||||
|
||||
@@ -3,7 +3,6 @@ use actix_web::http::header::q;
|
||||
use clap::builder::TypedValueParser;
|
||||
use minijinja::context;
|
||||
use serde::Deserialize;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use log::info;
|
||||
use resource::resource_str;
|
||||
@@ -56,16 +55,6 @@ pub async fn actions_partials(
|
||||
tmpl_env.render(template_location.as_str(), ctx)
|
||||
}
|
||||
|
||||
#[actix_web::get("/static/{file_name}")]
|
||||
pub async fn static_file(
|
||||
req: HttpRequest
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let file_name = req.match_info().get("file_name").unwrap_or(&"404.html".to_string()).to_string();
|
||||
let template_location = format!("static/{:}", file_name);
|
||||
info!("Getting static file: {:?}", file_name);
|
||||
Ok(template_location)
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Event1{
|
||||
|
||||
Reference in new issue
Block a user