fix: dashboard server picks up installed files without restart (#1066)
The dashboard HTTP server checked for index.html once at startup and cached the result. If the server started before `dashboard install`, it permanently served the "not installed" fallback page. Check for installed dashboard files on each request instead, so `dashboard install` takes effect immediately on a running server. Fixes #1065 Co-authored-by: ctate <366502+ctate@users.noreply.github.com>
This commit is contained in:
@@ -1489,14 +1489,7 @@ pub async fn run_dashboard_server(port: u16) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let dashboard_dir = {
|
let dashboard_dir: Arc<PathBuf> = Arc::from(get_dashboard_dir());
|
||||||
let dir = get_dashboard_dir();
|
|
||||||
if dir.join("index.html").exists() {
|
|
||||||
Some(Arc::from(dir))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let Ok((stream, _addr)) = listener.accept().await else {
|
let Ok((stream, _addr)) = listener.accept().await else {
|
||||||
@@ -1511,7 +1504,7 @@ pub async fn run_dashboard_server(port: u16) {
|
|||||||
|
|
||||||
async fn handle_dashboard_connection(
|
async fn handle_dashboard_connection(
|
||||||
mut stream: tokio::net::TcpStream,
|
mut stream: tokio::net::TcpStream,
|
||||||
dashboard_dir: Option<Arc<PathBuf>>,
|
dashboard_dir: Arc<PathBuf>,
|
||||||
) {
|
) {
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
|
|
||||||
@@ -1566,22 +1559,20 @@ async fn handle_dashboard_connection(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dir_ref = dashboard_dir.as_deref();
|
|
||||||
let (status, content_type, body): (&str, &str, Vec<u8>) = if path == "/api/sessions" {
|
let (status, content_type, body): (&str, &str, Vec<u8>) = if path == "/api/sessions" {
|
||||||
(
|
(
|
||||||
"200 OK",
|
"200 OK",
|
||||||
"application/json; charset=utf-8",
|
"application/json; charset=utf-8",
|
||||||
discover_sessions().into_bytes(),
|
discover_sessions().into_bytes(),
|
||||||
)
|
)
|
||||||
|
} else if dashboard_dir.join("index.html").exists() {
|
||||||
|
serve_static_file(&dashboard_dir, path)
|
||||||
} else {
|
} else {
|
||||||
match dir_ref {
|
(
|
||||||
Some(dir) => serve_static_file(dir, path),
|
"200 OK",
|
||||||
None => (
|
"text/html; charset=utf-8",
|
||||||
"200 OK",
|
DASHBOARD_NOT_INSTALLED_HTML.as_bytes().to_vec(),
|
||||||
"text/html; charset=utf-8",
|
)
|
||||||
DASHBOARD_NOT_INSTALLED_HTML.as_bytes().to_vec(),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = format!(
|
let response = format!(
|
||||||
|
|||||||
Reference in New Issue
Block a user