Skip to content

Commit

Permalink
Make HTTPS optional #192
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Oct 25, 2021
1 parent 89d3a4d commit 3ada0fe
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
2 changes: 2 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod content_types;
mod errors;
mod handlers;
mod helpers;
#[cfg(feature = "https")]
mod https;
mod jsonerrors;
mod process;
Expand Down
34 changes: 21 additions & 13 deletions server/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3ada0fe

Please sign in to comment.