Skip to content

Commit 19329be

Browse files
committed
server: allow customizing the address and port bound
1 parent cd1e5ec commit 19329be

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/cli.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crater::toolchain::Toolchain;
2323
use failure::{bail, Error, Fallible};
2424
use rustwide::{cmd::SandboxImage, Workspace, WorkspaceBuilder};
2525
use std::collections::HashSet;
26+
use std::net::SocketAddr;
2627
use std::path::PathBuf;
2728
use std::str::FromStr;
2829
use std::time::Duration;
@@ -265,7 +266,15 @@ pub enum Crater {
265266
},
266267

267268
#[structopt(name = "server")]
268-
Server,
269+
Server {
270+
#[structopt(
271+
name = "bind",
272+
long = "bind",
273+
short = "b",
274+
help = "The address and port to bind to."
275+
)]
276+
bind: Option<SocketAddr>,
277+
},
269278

270279
#[structopt(name = "agent")]
271280
Agent {
@@ -589,9 +598,9 @@ impl Crater {
589598
bail!("missing experiment: {}", ex.0);
590599
}
591600
}
592-
Crater::Server => {
601+
Crater::Server { bind } => {
593602
let config = Config::load()?;
594-
server::run(config)?;
603+
server::run(config, bind.unwrap_or(([127, 0, 0, 1], 8000).into()))?;
595604
}
596605
Crater::Agent {
597606
ref url,

src/server/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use http::{self, header::HeaderValue, Response};
2121
use hyper::Body;
2222
use metrics::Metrics;
2323
use std::sync::{Arc, Mutex};
24+
use std::net::SocketAddr;
2425
use warp::{self, Filter};
2526

2627
lazy_static! {
@@ -49,7 +50,7 @@ pub struct Data {
4950
pub metrics: Metrics,
5051
}
5152

52-
pub fn run(config: Config) -> Fallible<()> {
53+
pub fn run(config: Config, bind: SocketAddr) -> Fallible<()> {
5354
let db = Database::open()?;
5455
let tokens = tokens::Tokens::load()?;
5556
let github = GitHubApi::new(&tokens);
@@ -77,7 +78,7 @@ pub fn run(config: Config) -> Fallible<()> {
7778
data.reports_worker.spawn(data.clone());
7879
cronjobs::spawn(data.clone());
7980

80-
info!("running server...");
81+
info!("running server on {}...", bind);
8182

8283
let data = Arc::new(data);
8384

@@ -100,7 +101,7 @@ pub fn run(config: Config) -> Fallible<()> {
100101
resp
101102
});
102103

103-
warp::serve(routes).run(([127, 0, 0, 1], 8000));
104+
warp::serve(routes).run(bind);
104105

105106
Ok(())
106107
}

0 commit comments

Comments
 (0)