From: Geoffrey Allott Date: Thu, 1 Apr 2021 16:34:36 +0000 (+0100) Subject: allow configuring cache on/off X-Git-Url: https://git.pointlesshacks.com/?a=commitdiff_plain;h=758f802755f2cc11fb7016c0f3592c3e29b34815;p=pokerwave.git allow configuring cache on/off --- diff --git a/pokerwave.toml b/pokerwave.toml index 718a42d..9e62b95 100644 --- a/pokerwave.toml +++ b/pokerwave.toml @@ -10,3 +10,4 @@ #site = "site" #cert = "cert/cert.pem" #key = "cert/key.pem" +#cache = false diff --git a/src/config.rs b/src/config.rs index bef5394..df917f2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,10 +66,12 @@ pub struct ServerConfig { pub cert: Option, #[serde(default)] pub key: Option, + #[serde(default)] + pub cache: bool, } impl Default for ServerConfig { fn default() -> Self { - Self { bind: default_bind_addr(), site: default_site_path(), cert: None, key: None } + Self { bind: default_bind_addr(), site: default_site_path(), cert: None, key: None, cache: false } } } diff --git a/src/main.rs b/src/main.rs index 559a46b..cc36400 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,7 +143,11 @@ async fn main() -> Result<(), tide::Error> { let server: Pin>>> = if run_server { let mut app = tide::with_state(server); - app.at("/").with(After(append_cache_control)).serve_dir(&config.server.site)?; + if config.server.cache { + app.at("/").with(After(append_cache_control)).serve_dir(&config.server.site)?; + } else { + app.at("/").serve_dir(&config.server.site)?; + } app.at("/").with(After(append_cache_control)).serve_file(config.server.site.join("index.html"))?; app.at("/api").get(WebSocket::new(new_client)); app.with(After(serve_404));