From 9203dd3ef7b62489116e7b7fe0b9d288c3389c78 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 26 Sep 2021 02:04:27 +0300 Subject: 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. --- src/main.rs | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'src/main.rs') 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); + } } -- cgit 1.4.1