Skip to content

Commit 0eaee96

Browse files
committed
add host option when serving
1 parent eda106e commit 0eaee96

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

shai-cli/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ enum Commands {
131131
},
132132
/// Start HTTP server with SSE streaming
133133
Serve {
134+
/// Host to bind to (0.0.0.0 for all interfaces, 127.0.0.1 for localhost only)
135+
#[arg(long, default_value = "127.0.0.1")]
136+
host: String,
134137
/// Port to bind to
135138
#[arg(short, long, default_value = "3000")]
136139
port: u16,
@@ -176,8 +179,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
176179
let command_str = command.join(" ");
177180
handle_postcmd(exit_code, command_str).await?;
178181
},
179-
Some(Commands::Serve { port, agent, ephemeral }) => {
180-
handle_serve(port, agent, ephemeral).await?;
182+
Some(Commands::Serve { host, port, agent, ephemeral }) => {
183+
handle_serve(host, port, agent, ephemeral).await?;
181184
},
182185
None => {
183186
// Check for stdin input or trailing arguments
@@ -464,7 +467,7 @@ pub async fn handle_postcmd(exit_code: i32, command: String) -> Result<(), Box<d
464467
Ok(())
465468
}
466469

467-
async fn handle_serve(port: u16, agent: Option<String>, ephemeral: bool) -> Result<(), Box<dyn std::error::Error>> {
470+
async fn handle_serve(host: String, port: u16, agent: Option<String>, ephemeral: bool) -> Result<(), Box<dyn std::error::Error>> {
468471
// Initialize tracing for HTTP server logs
469472
tracing_subscriber::fmt()
470473
.with_target(false)
@@ -474,7 +477,7 @@ async fn handle_serve(port: u16, agent: Option<String>, ephemeral: bool) -> Resu
474477

475478
println!("{}", logo_cyan());
476479

477-
let addr = format!("127.0.0.1:{}", port);
480+
let addr = format!("{}:{}", host, port);
478481
let config = shai_http::ServerConfig::new(addr)
479482
.with_ephemeral(ephemeral)
480483
.with_max_sessions(Some(1));

0 commit comments

Comments
 (0)