Skip to content

Commit 2d719cf

Browse files
fix: version redirect
1 parent e308df5 commit 2d719cf

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

crates/api/src/routes/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod attestation;
44
pub mod oauth;
55
pub mod users;
66

7-
use axum::{middleware::from_fn_with_state, response::Redirect, routing::get, Json, Router};
7+
use axum::{middleware::from_fn_with_state, routing::get, Json, Router};
88
use serde::Serialize;
99
use tower_http::cors::{Any, CorsLayer};
1010
use utoipa::ToSchema;
@@ -78,8 +78,6 @@ pub fn create_router_with_cors(app_state: AppState, allowed_origins: Vec<String>
7878

7979
// Build the base router
8080
let router = Router::new()
81-
// Redirect root to /?v=1 to workaround the cache issue
82-
.route("/", get(|| async { Redirect::temporary("/?v=1") }))
8381
.route("/health", get(health_check))
8482
.nest("/v1/auth", auth_routes)
8583
.nest("/v1/users", user_routes)

crates/api/src/static_files.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use axum::{
22
body::Body,
33
http::{header, Request, StatusCode},
4-
response::{IntoResponse, Response},
4+
response::{IntoResponse, Redirect, Response},
55
};
66
use std::{env, path::PathBuf};
77
use tower::ServiceExt;
@@ -19,6 +19,17 @@ fn frontend_dir() -> PathBuf {
1919
/// Serve static files with SPA fallback and proper cache headers.
2020
pub async fn static_handler(req: Request<Body>) -> Response {
2121
let frontend_dir = frontend_dir();
22+
let uri = req.uri().clone();
23+
24+
let needs_version_redirect = uri.path() == "/"
25+
&& uri
26+
.query()
27+
.map(|q| !q.split('&').any(|pair| pair.starts_with("v=")))
28+
.unwrap_or(true);
29+
30+
if needs_version_redirect {
31+
return Redirect::temporary("/?v=1").into_response();
32+
}
2233

2334
let has_extension = req
2435
.uri()

0 commit comments

Comments
 (0)