Block pages indexing

This commit is contained in:
2022-04-23 20:41:31 +02:00
parent 48112dfed7
commit 234e77d08a
5 changed files with 17 additions and 4 deletions

View File

@ -1,11 +1,17 @@
use std::path::Path;
use actix_web::{web, HttpResponse};
use include_dir::{include_dir, Dir};
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) {
@ -17,4 +23,4 @@ pub async fn assets_route(path: web::Path<String>) -> HttpResponse {
.body(file.contents())
}
}
}
}

View File

@ -104,6 +104,7 @@ async fn main() -> std::io::Result<()> {
// main route
.route("/", web::get()
.to(|| async { HttpResponse::Found().append_header(("Location", "/settings")).finish() }))
.route("/robots.txt", web::get().to(assets_controller::robots_txt))
// health route
.service(health)