Skip to content

Commit ea0032f

Browse files
committed
expose non tls port
1 parent b4a368e commit ea0032f

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

aggregation_mode/gateway/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct Config {
1414
pub tls_cert_path: String,
1515
#[cfg(feature = "tls")]
1616
pub tls_key_path: String,
17+
#[cfg(feature = "tls")]
18+
pub tls_port: u16,
1719
}
1820

1921
impl Config {

aggregation_mode/gateway/src/http.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl GatewayServer {
8686

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

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

99-
#[cfg(feature = "tls")]
100-
let protocol = "https";
101-
#[cfg(not(feature = "tls"))]
102-
let protocol = "http";
103-
104-
tracing::info!(
105-
"Starting server at {}://{}:{}",
106-
protocol,
107-
self.config.ip,
108-
self.config.port
109-
);
110-
11199
let server = HttpServer::new(move || {
112100
App::new()
113101
.app_data(Data::new(state.clone()))
@@ -121,21 +109,36 @@ impl GatewayServer {
121109
});
122110

123111
#[cfg(feature = "tls")]
124-
let server = {
112+
{
113+
let tls_port = self.config.tls_port;
114+
tracing::info!("Starting HTTP server at http://{}:{}", self.config.ip, http_port);
115+
tracing::info!("Starting HTTPS server at https://{}:{}", self.config.ip, tls_port);
116+
125117
let tls_config =
126118
Self::load_tls_config(&self.config.tls_cert_path, &self.config.tls_key_path)
127119
.expect("Failed to load TLS configuration");
120+
128121
server
129-
.bind_rustls_0_23((self.config.ip.as_str(), port), tls_config)
130-
.expect("To bind socket correctly with TLS")
131-
};
122+
.bind((self.config.ip.as_str(), http_port))
123+
.expect("To bind HTTP socket correctly")
124+
.bind_rustls_0_23((self.config.ip.as_str(), tls_port), tls_config)
125+
.expect("To bind HTTPS socket correctly with TLS")
126+
.run()
127+
.await
128+
.expect("Server to never end");
129+
}
132130

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

138-
server.run().await.expect("Server to never end");
135+
server
136+
.bind((self.config.ip.as_str(), http_port))
137+
.expect("To bind HTTP socket correctly")
138+
.run()
139+
.await
140+
.expect("Server to never end");
141+
}
139142
}
140143

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

0 commit comments

Comments
 (0)