diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-15 13:33:01 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-15 13:33:01 +0200 |
commit | bde80a475840c1d41f55e07fe0b8ff38119e76c6 (patch) | |
tree | 402737bf6b306fcf75e485489b79c9bcb37bae67 | |
parent | 3bfc876c63871f5e3e497df2aeb33721acb90c0b (diff) | |
download | keks-meet-bde80a475840c1d41f55e07fe0b8ff38119e76c6.tar keks-meet-bde80a475840c1d41f55e07fe0b8ff38119e76c6.tar.bz2 keks-meet-bde80a475840c1d41f55e07fe0b8ff38119e76c6.tar.zst |
read config at runtime
-rw-r--r-- | readme.md | 10 | ||||
-rw-r--r-- | server/Cargo.toml | 4 | ||||
-rw-r--r-- | server/makefile | 4 | ||||
-rw-r--r-- | server/src/main.rs | 15 |
4 files changed, 23 insertions, 10 deletions
@@ -34,16 +34,16 @@ should help: pacman -S --needed esbuild rustup make coreutils; rustup install nightly git clone https://codeberg.org/metamuffin/keks-meet.git cd keks-meet -cp config/client.example.toml config/client.toml # use the example config. the defaults work. -make install-server # binaries will be copied to ~/.cargo/bin -# make install # installs the for-now-broken client applications too +make install-server # binaries will be installed to ~/.cargo/bin +keks-meet-server config/client.example.toml ``` When changing code, use `make watch` to re-build things automatically as needed. (requires `cargo install systemfd cargo-watch`) -The client configuration file (`config/client.toml`) configures the client and -requires server recompilation on change for now. +The server takes a path to the configuration file as its first argument unless +the `embed_config` feature is used. In that case, the configuration is read from +`config/config.toml` and embedded into the server binary. The server's bind address can be controlled using the `BIND` environment variable. When compilin without debug assertions (release) all assets are diff --git a/server/Cargo.toml b/server/Cargo.toml index 498f85d..d8a08a5 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -16,3 +16,7 @@ serde_json = "1.0.99" include_dir = "0.7.3" toml = "0.7.5" grass = "0.12.4" + +[features] +default = [] +embed_config = [] diff --git a/server/makefile b/server/makefile index 6097a10..74876ae 100644 --- a/server/makefile +++ b/server/makefile @@ -4,8 +4,8 @@ release: target/release/keks-meet run: cargo +nightly run --release watch: - systemfd --no-pid -s http::8080 -- cargo watch -x '+nightly run' + systemfd --no-pid -s http::8080 -- cargo watch -x '+nightly run --features embed_config' watch-public: - systemfd --no-pid -s http::0.0.0.0:8080 -- cargo watch -x '+nightly run' + systemfd --no-pid -s http::0.0.0.0:8080 -- cargo watch -x '+nightly run --features embed_config' target/release/keks-meet: $(shell find src) Cargo.toml cargo +nightly build --release diff --git a/server/src/main.rs b/server/src/main.rs index d36681b..eb6e502 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -41,8 +41,16 @@ fn main() { async fn run() { env_logger::init_from_env("LOG"); - let config: Config = toml::from_str(include_str!("../../config/config.toml")) - .expect("client configuration invalid"); + #[cfg(feature = "embed_config")] + let config = include_str!("../../config/config.toml").to_string(); + #[cfg(not(feature = "embed_config"))] + let config = std::fs::read_to_string( + std::env::args() + .nth(1) + .expect("first argument should be the configuration"), + ) + .expect("cannot read configuration"); + let config: Config = toml::from_str(&config).expect("configuration invalid"); let client_config_json = serde_json::to_string(&config).unwrap(); let client_config_css = css_overrides(&config.appearance); @@ -55,7 +63,8 @@ async fn run() { .map(signaling_connect); let index: _ = warp::path!().and(s_file!("client-web/public/start.html", "text/html")); - let favicon: _ = warp::path!("favicon.ico").and(s_file!("client-web/public/favicon.ico", "image/avif")); + let favicon: _ = + warp::path!("favicon.ico").and(s_file!("client-web/public/favicon.ico", "image/avif")); let room: _ = warp::path!("room").and(s_file!("client-web/public/app.html", "text/html")); let assets: _ = warp::path("assets").and(s_asset_dir!()); let sw_script: _ = warp::path("sw.js").and(s_file!( |