diff --git a/README.md b/README.md index ec49ffa..9c2fcf1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Features : * [x] TOTP (authenticator app) * [x] Using a security key (Webauthn) * [ ] Fully responsive webui -* [ ] `robots.txt` file to prevent indexing +* [x] `robots.txt` prevents indexing ## Compiling You will need the Rust toolchain to compile this project. To build it for production, just run: diff --git a/assets/robots.txt b/assets/robots.txt new file mode 100644 index 0000000..77470cb --- /dev/null +++ b/assets/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / \ No newline at end of file diff --git a/src/controllers/assets_controller.rs b/src/controllers/assets_controller.rs index 2ca760d..cef5e57 100644 --- a/src/controllers/assets_controller.rs +++ b/src/controllers/assets_controller.rs @@ -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) -> 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) -> HttpResponse { .body(file.contents()) } } -} +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 829eb0e..69f7989 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) diff --git a/templates/login/base_login_page.html b/templates/login/base_login_page.html index bd71b5f..ea9caff 100644 --- a/templates/login/base_login_page.html +++ b/templates/login/base_login_page.html @@ -4,6 +4,10 @@ + + + + {{ _p.app_name }} - {{ _p.page_title }}