Skip to content

Commit

Permalink
Noindex api
Browse files Browse the repository at this point in the history
  • Loading branch information
randomairborne committed Feb 7, 2024
1 parent 311f01c commit b8f42d6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async fn main() {
let client_ip_var = std::env::var("CLIENT_IP_HEADER").ok();
let state = AppState::new(client_ip_var);
let app = axum::Router::new()
.route("/", get(home))
.route("/raw", any(raw))
.layer(axum::middleware::from_fn(noindex))
.route("/", get(home))
.layer(axum::middleware::from_fn(nocors))
.with_state(state.clone());
println!("Listening on http://{addr} for ip requests");
Expand Down Expand Up @@ -87,6 +88,14 @@ async fn nocors(request: Request, next: Next) -> Response {
response
}

async fn noindex(req: Request, next: Next) -> Response {
let mut resp = next.run(req).await;
let name = HeaderName::from_static("X-Robots-Tag");
let value = HeaderValue::from_static("noindex");
resp.headers_mut().insert(name, value);
resp
}

#[derive(Clone)]
pub struct AppState {
header: Option<Arc<HeaderName>>,
Expand Down

0 comments on commit b8f42d6

Please sign in to comment.