2022-03-30 08:14:39 +00:00
|
|
|
use std::path::Path;
|
2022-03-30 07:40:46 +00:00
|
|
|
|
2022-04-23 18:41:31 +00:00
|
|
|
use actix_web::{HttpResponse, web};
|
|
|
|
use include_dir::{Dir, include_dir};
|
2022-03-30 07:40:46 +00:00
|
|
|
|
|
|
|
/// Assets directory
|
|
|
|
static ASSETS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/assets");
|
|
|
|
|
2022-04-23 18:41:31 +00:00
|
|
|
pub async fn robots_txt() -> HttpResponse {
|
|
|
|
HttpResponse::Ok()
|
|
|
|
.content_type("text/plain")
|
|
|
|
.body(include_str!("../../assets/robots.txt"))
|
|
|
|
}
|
|
|
|
|
2022-03-30 08:14:39 +00:00
|
|
|
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"),
|
2022-03-30 07:40:46 +00:00
|
|
|
Some(file) => {
|
2022-03-30 08:14:39 +00:00
|
|
|
let res = mime_guess::from_path(path).first_or_octet_stream();
|
|
|
|
HttpResponse::Ok()
|
|
|
|
.content_type(res.to_string())
|
|
|
|
.body(file.contents())
|
2022-03-30 07:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-23 18:41:31 +00:00
|
|
|
}
|