Files
BasicOIDC/src/controllers/assets_controller.rs
Pierre HUBERT b77e7895b7
Some checks failed
continuous-integration/drone/push Build is failing
Rust Edition 2024
2025-03-28 14:40:35 +01:00

27 lines
799 B
Rust

use std::path::Path;
use actix_web::{HttpResponse, web};
use include_dir::{Dir, include_dir};
/// Assets directory
static ASSETS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/assets");
pub async fn robots_txt() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/plain")
.body(include_str!("../../assets/robots.txt"))
}
pub async fn assets_route(path: web::Path<String>) -> HttpResponse {
let path: &Path = path.as_ref().as_ref();
match ASSETS_DIR.get_file(path) {
None => HttpResponse::NotFound().body("404 Not found"),
Some(file) => {
let res = mime_guess::from_path(path).first_or_octet_stream();
HttpResponse::Ok()
.content_type(res.to_string())
.body(file.contents())
}
}
}