diff --git a/CHANGELOG.md b/CHANGELOG.md index c41d9027c..ab90305f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ List of changes for this repo, including `atomic-cli`, `atomic-server` and `atomic-lib`. By far most changes relate to `atomic-server`, so if not specified, assume the changes are relevant only for the server. +## v0.27.2 + +- Make HTTPS optional #192 + ## v0.27.1 - Fix bootstrapping issue #193 diff --git a/server/Cargo.toml b/server/Cargo.toml index 0d0d86360..b3e64146f 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/joepio/atomic-data-rust" version = "0.27.1" [dependencies] -acme-lib = "0.8.1" +acme-lib = {version = "0.8.1", optional = true} actix = "0.10.0" actix-cors = "0.5.4" actix-files = "0.5.0" @@ -26,11 +26,13 @@ log = "0.4.11" open = {version = "2.0.1", optional = true} promptly = "0.3.0" regex = "1.4.2" -rustls = "0.18.1" +rustls = {version = "0.18.1", optional = true} serde = {version = "1.0.118", features = ["derive"]} serde_json = "1.0.60" tokio = {version = "1.4.0", features = ["time"]} tray-item = {version = "0.4.0-alpha", optional = true} [features] +default = ["https"] desktop = ["tray-item", "open"] +https = ["acme-lib", "rustls"] diff --git a/server/README.md b/server/README.md index 758c3a310..21d5af7fa 100644 --- a/server/README.md +++ b/server/README.md @@ -83,6 +83,8 @@ cp default.env .env cargo run # Or tun the extra-cool desktop version with a presence in your app tray cargo run --features desktop +# If you don't need HTTPS (or don't have OpenSSL available on your device) +cargo run --no-default-features ``` Troubleshooting compiling from source: diff --git a/server/src/main.rs b/server/src/main.rs index ea9b13af0..0b8a9e366 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -6,6 +6,7 @@ mod content_types; mod errors; mod handlers; mod helpers; +#[cfg(feature = "https")] mod https; mod jsonerrors; mod process; diff --git a/server/src/serve.rs b/server/src/serve.rs index 93b7bb7dd..1888fd22b 100644 --- a/server/src/serve.rs +++ b/server/src/serve.rs @@ -58,20 +58,28 @@ pub async fn serve(config: crate::config::Config) -> AtomicResult<()> { let message = format!("{}\n\nVisit {}\n\n", BANNER, config.local_base_url); if config.opts.https { - // If there is no certificate file, or the certs are too old, start HTTPS initialization - if std::fs::File::open(&config.cert_path).is_err() || crate::https::check_expiration_certs() - { - crate::https::cert_init_server(&config).await?; + if cfg!(feature = "https") { + #[cfg(feature = "https")] + { + // If there is no certificate file, or the certs are too old, start HTTPS initialization + if std::fs::File::open(&config.cert_path).is_err() + || crate::https::check_expiration_certs() + { + crate::https::cert_init_server(&config).await?; + } + let https_config = crate::https::get_https_config(&config) + .expect("HTTPS TLS Configuration with Let's Encrypt failed."); + let endpoint = format!("{}:{}", config.opts.ip, config.opts.port_https); + println!("{}", message); + server + .bind_rustls(&endpoint, https_config) + .expect(&*format!("Cannot bind to endpoint {}", &endpoint)) + .run() + .await?; + } + } else { + return Err("The HTTPS feature has been disabled for this build. Please compile atomic-server with the HTTP feature. `cargo install atomic-server`".into()); } - let https_config = crate::https::get_https_config(&config) - .expect("HTTPS TLS Configuration with Let's Encrypt failed."); - let endpoint = format!("{}:{}", config.opts.ip, config.opts.port_https); - println!("{}", message); - server - .bind_rustls(&endpoint, https_config) - .expect(&*format!("Cannot bind to endpoint {}", &endpoint)) - .run() - .await?; } else { let endpoint = format!("{}:{}", config.opts.ip, config.opts.port); println!("{}", message);