Skip to content

Commit

Permalink
fix file server
Browse files Browse the repository at this point in the history
  • Loading branch information
aschey committed Apr 2, 2024
1 parent b90b7e0 commit 227e9fd
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions platuned/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,30 @@ async fn run_file_service(
shutdown_rx: BroadcastEventStore<Signal>,
) -> Result<()> {
let addr: SocketAddr = "0.0.0.0:50050".parse().expect("failed to parse address");
info!("Running file server on {addr}");
let mut shutdown_rx = shutdown_rx.subscribe_events();

info!("Running file server on {addr}");
let mut app = axum::Router::new();
for folder in folders {
app = app.nest_service(&format!("/{folder}"), ServeDir::new(folder));
let root_path = "/";
match &folders[..] {
[] => {}
[folder] => {
app = app.nest_service(root_path, ServeDir::new(folder));
}
[folder, fallback] => {
app = app.nest_service(
root_path,
ServeDir::new(folder).fallback(ServeDir::new(fallback)),
);
}
[first, second, rest @ ..] => {
let mut serve_dir = ServeDir::new(first).fallback(ServeDir::new(second));
for folder in rest {
serve_dir = serve_dir.fallback(ServeDir::new(folder));
}
app = app.nest_service(root_path, serve_dir);
}
}

let listener = tokio::net::TcpListener::bind(&addr)
.await
.wrap_err(format!("Failed to bind to {addr}"))?;
Expand Down

0 comments on commit 227e9fd

Please sign in to comment.