summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-10-09 18:28:44 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-10-09 18:28:44 -0500
commit859fd855e1a819280931ffbb6ae98098b2774269 (patch)
tree745bf82c5789e60584e0867a25989243876f8f9f /src/main.rs
parentb94f8e694bf01f5dba9ce2c01f589463a3dfbc69 (diff)
feat: make file server optional
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 46adbfa..85ff708 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -22,10 +22,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let state = AppState::spawn_services(config.services);
- let router = statsrv::router()
- .with_state(state)
- .nest_service("/", ServeDir::new(config.root))
- .layer(tower_http::trace::TraceLayer::new_for_http());
+ let mut router = statsrv::router().with_state(state);
+
+ if let Some(path) = config.serve_dir {
+ router = router.nest_service("/", ServeDir::new(path));
+ }
+
+ router = router.layer(tower_http::trace::TraceLayer::new_for_http());
let listener = tokio::net::TcpListener::bind(config.address).await.unwrap();
tracing::info!("listening on {}", listener.local_addr().unwrap());
@@ -36,7 +39,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Debug, Clone, serde::Deserialize)]
#[serde(default)]
pub struct Config {
- pub root: PathBuf,
+ pub serve_dir: Option<PathBuf>,
pub address: String,
pub services: HashMap<String, ServiceConfig>,
}
@@ -60,7 +63,7 @@ impl Config {
impl Default for Config {
fn default() -> Self {
Self {
- root: PathBuf::from("./"),
+ serve_dir: None,
address: String::from("127.0.0.1:8080"),
services: Default::default(),
}