Skip to content

Commit 3cc1e31

Browse files
API noindex
1 parent cd418c8 commit 3cc1e31

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ mod structures;
44

55
use std::{borrow::Cow, net::SocketAddr, sync::Arc};
66

7+
use axum::extract::Request;
8+
use axum::http::{HeaderName, HeaderValue};
9+
use axum::middleware::Next;
10+
use axum::response::Response;
711
use axum::{extract::Path, http::StatusCode, response::IntoResponse, routing::get};
812
use libmcping::{Bedrock, Java};
913
use reqwest::header::HeaderMap;
@@ -51,6 +55,7 @@ async fn main() {
5155
.route("/api/java/:address", get(handle_java_ping))
5256
.route("/api/bedrock/:address", get(handle_bedrock_ping))
5357
.route("/api/services", get(services::handle_mcstatus))
58+
.layer(axum::middleware::from_fn(noindex))
5459
.fallback_service(serve_dir)
5560
.with_state(current_mcstatus);
5661
let socket_address = SocketAddr::from((
@@ -67,6 +72,14 @@ async fn main() {
6772
.unwrap();
6873
}
6974

75+
async fn noindex(req: Request, next: Next) -> Response {
76+
let mut resp = next.run(req).await;
77+
let name = HeaderName::from_static("X-Robots-Tag");
78+
let value = HeaderValue::from_static("noindex");
79+
resp.headers_mut().insert(name, value);
80+
resp
81+
}
82+
7083
async fn handle_java_ping(Path(address): Path<String>) -> Result<impl IntoResponse, Failure> {
7184
let (latency, response) = match libmcping::tokio::get_status(Java {
7285
server_address: address,

0 commit comments

Comments
 (0)