2022-11-08 21:30:16 +00:00
|
|
|
use actix_web::{web, HttpResponse, Responder};
|
2022-11-01 18:56:07 +00:00
|
|
|
use mime_guess::from_path;
|
|
|
|
use rust_embed::RustEmbed;
|
2022-06-03 16:24:34 +00:00
|
|
|
|
2022-11-01 18:56:07 +00:00
|
|
|
#[derive(RustEmbed)]
|
|
|
|
#[folder = "templates/assets/"]
|
|
|
|
struct Asset;
|
2022-06-03 16:24:34 +00:00
|
|
|
|
2022-11-01 18:56:07 +00:00
|
|
|
fn handle_embedded_file(path: &str) -> HttpResponse {
|
|
|
|
match Asset::get(path) {
|
|
|
|
Some(content) => HttpResponse::Ok()
|
|
|
|
.content_type(from_path(path).first_or_octet_stream().as_ref())
|
|
|
|
.body(content.data.into_owned()),
|
|
|
|
None => HttpResponse::NotFound().body("404 Not Found"),
|
|
|
|
}
|
2022-10-01 05:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-01 18:56:07 +00:00
|
|
|
#[actix_web::get("/static/{_:.*}")]
|
|
|
|
async fn static_resources(path: web::Path<String>) -> impl Responder {
|
|
|
|
handle_embedded_file(path.as_str())
|
2022-06-03 16:24:34 +00:00
|
|
|
}
|