From 4a9107237b7d4f356be4f247b51759299a4b185e Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Tue, 2 Jul 2024 17:46:36 +0200 Subject: [PATCH] fix: if hitting path before login, redirect to login --- kinode/src/http/server.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/kinode/src/http/server.rs b/kinode/src/http/server.rs index 936c2ef02..2da97f11e 100644 --- a/kinode/src/http/server.rs +++ b/kinode/src/http/server.rs @@ -218,7 +218,6 @@ pub async fn http_server( )); while let Some(km) = recv_in_server.recv().await { - // we *can* move this into a dedicated task, but it's not necessary handle_app_message( km, http_response_senders.clone(), @@ -585,10 +584,28 @@ async fn http_handler( &jwt_secret_bytes, ) { // redirect to login page so they can get an auth token - return Ok(warp::http::Response::builder() - .status(StatusCode::OK) - .body(login_html.to_string()) - .into_response()); + if original_path == "" { + return Ok(warp::http::Response::builder() + .status(StatusCode::OK) + .body(login_html.to_string()) + .into_response()); + } else { + return Ok(warp::http::Response::builder() + .status(StatusCode::TEMPORARY_REDIRECT) + .header( + "Location", + format!( + "{}://{}", + match headers.get("X-Forwarded-Proto") { + Some(proto) => proto.to_str().unwrap_or("http"), + None => "http", + }, + host, + ), + ) + .body(vec![]) + .into_response()); + } } } }