Skip to content

Commit 38b615a

Browse files
Fix indexing tags
1 parent 33c5bf5 commit 38b615a

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Cargo.lock

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ axum-extra = "0.9"
2121
serde_json = "1"
2222
thiserror = "1"
2323
tracing = "0.1"
24+
tower = "0.4"
2425
vss = "0.1"
2526

2627
[workspace]

src/main.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use parking_lot::RwLock;
2424
use reqwest::{header::HeaderMap, redirect::Policy, Client};
2525
use serde::{Deserialize, Serialize};
2626
use tokio::net::TcpListener;
27+
use tower::ServiceBuilder;
2728
use tower_http::services::ServeDir;
2829
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
2930

@@ -75,21 +76,25 @@ async fn main() {
7576
.precompressed_zstd()
7677
.fallback(handle_404.with_state(state.clone()));
7778
let app = Router::new()
78-
.route("/", get(root))
79-
.route_with_tsr("/api/", get(api_info))
80-
.route_with_tsr("/ping/:edition/:hostname", get(ping_page))
8179
.route("/ping/redirect", get(ping_redirect))
82-
.route("/internal/ping-frame/:edition/:hostname", get(ping_frame))
83-
.route("/internal/ping-markup/:edition/:hostname", get(ping_markup))
8480
.route("/api/:address", get(handle_java_ping))
8581
.route("/api/java/:address", get(handle_java_ping))
8682
.route("/api/bedrock/:address", get(handle_bedrock_ping))
8783
.route("/api/java/", get(no_address))
8884
.route("/api/bedrock/", get(no_address))
8985
.route("/api/services", get(services::handle_mcstatus))
90-
.layer(axum::middleware::from_fn(noindex_cache))
86+
.layer(axum::middleware::from_fn(noindex))
87+
.route("/", get(root))
88+
.route_with_tsr("/api/", get(api_info))
89+
.route_with_tsr("/ping/:edition/:hostname", get(ping_page))
90+
.route("/internal/ping-frame/:edition/:hostname", get(ping_frame))
91+
.route("/internal/ping-markup/:edition/:hostname", get(ping_markup))
9192
.fallback_service(serve_dir)
92-
.layer(axum::middleware::from_fn(csp))
93+
.layer(
94+
ServiceBuilder::new()
95+
.layer(axum::middleware::from_fn(csp))
96+
.layer(axum::middleware::from_fn(cache)),
97+
)
9398
.with_state(state);
9499
let socket_address = SocketAddr::from(([0, 0, 0, 0], port));
95100
let tcp = TcpListener::bind(socket_address).await.unwrap();
@@ -120,12 +125,10 @@ static CSP_VALUE: HeaderValue = HeaderValue::from_static(
120125
base-uri 'none';",
121126
);
122127

123-
async fn noindex_cache(req: Request, next: Next) -> Response {
128+
async fn noindex(req: Request, next: Next) -> Response {
124129
let mut resp = next.run(req).await;
125130
resp.headers_mut()
126131
.insert(ROBOTS_NAME.clone(), ROBOTS_VALUE.clone());
127-
resp.headers_mut()
128-
.insert(CACHE_CONTROL, CACHE_CONTROL_AGE.clone());
129132
resp
130133
}
131134

@@ -136,6 +139,13 @@ async fn csp(req: Request, next: Next) -> Response {
136139
resp
137140
}
138141

142+
async fn cache(req: Request, next: Next) -> Response {
143+
let mut resp = next.run(req).await;
144+
resp.headers_mut()
145+
.insert(CACHE_CONTROL, CACHE_CONTROL_AGE.clone());
146+
resp
147+
}
148+
139149
#[derive(Template)]
140150
#[template(path = "index.html")]
141151
pub struct RootTemplate {

0 commit comments

Comments
 (0)