diff options
author | Vika <vika@fireburn.ru> | 2021-09-26 02:04:27 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2021-09-26 02:06:56 +0300 |
commit | 9203dd3ef7b62489116e7b7fe0b9d288c3389c78 (patch) | |
tree | c958b9bd42241b4452262ddfe197b1e91d211cbb /src/main.rs | |
parent | 572435f7c8e1d613983309eca268c3f87ec5f00f (diff) | |
download | kittybox-9203dd3ef7b62489116e7b7fe0b9d288c3389c78.tar.zst |
Moved integration tests and allowed the binary to use file backend
Now the Redis dependencies are optional and only required if you want to test the backend or actually use it in production. The app displays a hint if you try to launch with an unsupported backend.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs index 0e57ed5..e91476b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,14 +10,14 @@ async fn main() -> Result<(), std::io::Error> { info!("Starting the kittybox server..."); - let redis_uri: String; - match env::var("REDIS_URI") { + let backend_uri: String; + match env::var("BACKEND_URI") { Ok(val) => { - debug!("Redis connection: {}", val); - redis_uri = val + debug!("Backend URI: {}", val); + backend_uri = val } Err(_) => { - error!("REDIS_URI is not set, cannot find a database"); + error!("BACKEND_URI is not set, cannot find a database"); std::process::exit(1); } }; @@ -63,13 +63,35 @@ async fn main() -> Result<(), std::io::Error> { let host = env::var("SERVE_AT") .ok() .unwrap_or_else(|| "0.0.0.0:8080".to_string()); - let app = kittybox::get_app_with_redis( - token_endpoint, - authorization_endpoint, - redis_uri, - media_endpoint, - internal_token, - ) - .await; - app.listen(host).await + + if backend_uri.starts_with("redis") { + #[cfg(redis)] + { + let app = kittybox::get_app_with_redis( + token_endpoint, + authorization_endpoint, + backend_uri, + media_endpoint, + internal_token, + ).await; + app.listen(host).await + } + #[cfg(not(redis))] + { + println!("The Redis backend was disabled at build-time. Please recompile the package with --features=redis."); + std::process::exit(1); + } + } else if backend_uri.starts_with("file") { + let app = kittybox::get_app_with_file( + token_endpoint, + authorization_endpoint, + backend_uri, + media_endpoint, + internal_token + ).await; + app.listen(host).await + } else { + println!("Unknown backend, not starting."); + std::process::exit(1); + } } |