summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.toml2
-rw-r--r--src/main.rs15
2 files changed, 10 insertions, 7 deletions
diff --git a/config.toml b/config.toml
index b60b25c..00a0866 100644
--- a/config.toml
+++ b/config.toml
@@ -1,4 +1,4 @@
-root = "assets"
+serve_dir = "assets"
address = "127.0.0.1:8080"
[services]
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(),
}