Skip to content

Commit fd81a55

Browse files
committed
feat: added http server host env variable
1 parent 8384458 commit fd81a55

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

adapter/rest/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ impl IdentifiableFlow for RequestRoute {
5555
#[async_trait]
5656
impl ServerTrait<HttpServerConfig> for HttpServer {
5757
async fn init(&mut self, ctx: &ServerContext<HttpServerConfig>) -> anyhow::Result<()> {
58-
self.http_server = Some(Server::new(ctx.server_config.port));
58+
log::info!("Initializing http server");
59+
self.http_server = Some(Server::new(ctx.server_config.host.clone(), ctx.server_config.port));
5960
Ok(())
6061
}
6162

6263
async fn run(&mut self, ctx: &ServerContext<HttpServerConfig>) -> anyhow::Result<()> {
6364
if let Some(server) = &mut self.http_server {
65+
log::info!("Running http server");
6466
server.register_async_closure({
6567
let store = Arc::clone(&ctx.adapter_store);
6668
move |request: HttpRequest| {
@@ -163,12 +165,14 @@ async fn execute_flow(
163165
#[derive(Clone)]
164166
struct HttpServerConfig {
165167
port: u16,
168+
host: String,
166169
}
167170

168171
impl LoadConfig for HttpServerConfig {
169172
fn load() -> Self {
170173
Self {
171174
port: env_with_default("HTTP_SERVER_PORT", 8082),
175+
host: env_with_default("HTTP_SERVER_HOST", String::from("0.0.0.0")),
172176
}
173177
}
174178
}

crates/http/src/server.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ where
2727
}
2828

2929
pub struct Server {
30+
host: String,
3031
port: u16,
3132
handlers: Arc<Vec<Box<dyn AsyncHandler>>>,
3233
shutdown_tx: Option<tokio::sync::broadcast::Sender<()>>,
3334
}
3435

3536
impl Server {
36-
pub fn new(port: u16) -> Self {
37+
pub fn new(host: String, port: u16) -> Self {
3738
Server {
39+
host,
3840
port,
3941
handlers: Arc::new(Vec::new()),
4042
shutdown_tx: None,
@@ -74,8 +76,8 @@ impl Server {
7476
}
7577

7678
async fn run_server(&self, shutdown_rx: &mut tokio::sync::broadcast::Receiver<()>) {
77-
let url = format!("127.0.0.1:{}", self.port);
78-
79+
let url = format!("{}:{}",self.host, self.port);
80+
log::info!("Starting http server on {}", &url);
7981
let listener = match TcpListener::bind(&url) {
8082
Ok(listener) => {
8183
listener

0 commit comments

Comments
 (0)