Skip to content

Commit e308df5

Browse files
fix: redirect root url
1 parent c788de6 commit e308df5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

crates/api/src/routes/mod.rs

Lines changed: 3 additions & 1 deletion
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, routing::get, Json, Router};
7+
use axum::{middleware::from_fn_with_state, response::Redirect, routing::get, Json, Router};
88
use serde::Serialize;
99
use tower_http::cors::{Any, CorsLayer};
1010
use utoipa::ToSchema;
@@ -78,6 +78,8 @@ 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") }))
8183
.route("/health", get(health_check))
8284
.nest("/v1/auth", auth_routes)
8385
.nest("/v1/users", user_routes)

crates/api/src/static_files.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +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 path = req.uri().path().to_owned();
23-
let is_root = path == "/";
2422

25-
let has_extension = path
23+
let has_extension = req
24+
.uri()
25+
.path()
2626
.rsplit('/')
2727
.next()
2828
.map(|segment| segment.contains('.'))
2929
.unwrap_or(false);
3030

3131
// Serve static files if they have an extension, otherwise fallback to the index.html file
32-
let result = if is_root {
33-
ServeFile::new(frontend_dir.join("index.html"))
34-
.oneshot(req)
35-
.await
36-
} else if has_extension {
32+
let result = if has_extension {
3733
ServeDir::new(frontend_dir.clone()).oneshot(req).await
3834
} else {
3935
ServeDir::new(frontend_dir.clone())
@@ -50,7 +46,7 @@ pub async fn static_handler(req: Request<Body>) -> Response {
5046
.map(|ct| ct.contains("text/html"))
5147
.unwrap_or(false);
5248
// Don't cache HTML files to allow for SPA updates
53-
let cache_value = if is_html || is_root {
49+
let cache_value = if is_html {
5450
"no-cache, no-store, must-revalidate"
5551
} else {
5652
"public, max-age=31536000, immutable"

0 commit comments

Comments
 (0)