@@ -4,6 +4,10 @@ mod structures;
4
4
5
5
use std:: { borrow:: Cow , net:: SocketAddr , sync:: Arc } ;
6
6
7
+ use axum:: extract:: Request ;
8
+ use axum:: http:: { HeaderName , HeaderValue } ;
9
+ use axum:: middleware:: Next ;
10
+ use axum:: response:: Response ;
7
11
use axum:: { extract:: Path , http:: StatusCode , response:: IntoResponse , routing:: get} ;
8
12
use libmcping:: { Bedrock , Java } ;
9
13
use reqwest:: header:: HeaderMap ;
@@ -51,6 +55,7 @@ async fn main() {
51
55
. route ( "/api/java/:address" , get ( handle_java_ping) )
52
56
. route ( "/api/bedrock/:address" , get ( handle_bedrock_ping) )
53
57
. route ( "/api/services" , get ( services:: handle_mcstatus) )
58
+ . layer ( axum:: middleware:: from_fn ( noindex) )
54
59
. fallback_service ( serve_dir)
55
60
. with_state ( current_mcstatus) ;
56
61
let socket_address = SocketAddr :: from ( (
@@ -67,6 +72,14 @@ async fn main() {
67
72
. unwrap ( ) ;
68
73
}
69
74
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
+
70
83
async fn handle_java_ping ( Path ( address) : Path < String > ) -> Result < impl IntoResponse , Failure > {
71
84
let ( latency, response) = match libmcping:: tokio:: get_status ( Java {
72
85
server_address : address,
0 commit comments