Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aggregation_mode/gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct Config {
pub tls_cert_path: String,
#[cfg(feature = "tls")]
pub tls_key_path: String,
#[cfg(feature = "tls")]
pub tls_port: u16,
}

impl Config {
Expand Down
57 changes: 36 additions & 21 deletions aggregation_mode/gateway/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl GatewayServer {

pub async fn start(&self) {
// Note: GatewayServer is thread safe so we can just clone it (no need to add mutexes)
let port = self.config.port;
let http_port = self.config.port;
let state = self.clone();

// Note: This creates a new Prometheus server different from the one created in GatewayServer::new. The created
Expand All @@ -96,18 +96,6 @@ impl GatewayServer {
.build()
.unwrap();

#[cfg(feature = "tls")]
let protocol = "https";
#[cfg(not(feature = "tls"))]
let protocol = "http";

tracing::info!(
"Starting server at {}://{}:{}",
protocol,
self.config.ip,
self.config.port
);

let server = HttpServer::new(move || {
App::new()
.app_data(Data::new(state.clone()))
Expand All @@ -121,21 +109,48 @@ impl GatewayServer {
});

#[cfg(feature = "tls")]
let server = {
{
let tls_port = self.config.tls_port;
tracing::info!(
"Starting HTTP server at http://{}:{}",
self.config.ip,
http_port
);
tracing::info!(
"Starting HTTPS server at https://{}:{}",
self.config.ip,
tls_port
);

let tls_config =
Self::load_tls_config(&self.config.tls_cert_path, &self.config.tls_key_path)
.expect("Failed to load TLS configuration");

server
.bind_rustls_0_23((self.config.ip.as_str(), port), tls_config)
.expect("To bind socket correctly with TLS")
};
.bind((self.config.ip.as_str(), http_port))
.expect("To bind HTTP socket correctly")
.bind_rustls_0_23((self.config.ip.as_str(), tls_port), tls_config)
.expect("To bind HTTPS socket correctly with TLS")
.run()
.await
.expect("Server to never end");
}

#[cfg(not(feature = "tls"))]
let server = server
.bind((self.config.ip.as_str(), port))
.expect("To bind socket correctly");
{
tracing::info!(
"Starting HTTP server at http://{}:{}",
self.config.ip,
http_port
);

server.run().await.expect("Server to never end");
server
.bind((self.config.ip.as_str(), http_port))
.expect("To bind HTTP socket correctly")
.run()
.await
.expect("Server to never end");
}
Comment thread
JuArce marked this conversation as resolved.
Outdated
}

// Returns an OK response (code 200), no matters what receives in the request
Expand Down
Loading