Parse http CLI args for HTTP server
This commit is contained in:
parent
2a04da8bf7
commit
3f27fd4edf
@ -140,6 +140,19 @@ impl ClientConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* HTTP related arguments */
|
||||||
|
|
||||||
|
if args.is_present("http") {
|
||||||
|
config.http_conf.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(listen_address) = args.value_of("http-address") {
|
||||||
|
config.http_conf.listen_address = listen_address.to_string();
|
||||||
|
}
|
||||||
|
if let Some(listen_port) = args.value_of("http-port") {
|
||||||
|
config.http_conf.listen_port = listen_port.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
match args.value_of("db") {
|
match args.value_of("db") {
|
||||||
Some("disk") => config.db_type = DBType::Disk,
|
Some("disk") => config.db_type = DBType::Disk,
|
||||||
Some("memory") => config.db_type = DBType::Memory,
|
Some("memory") => config.db_type = DBType::Memory,
|
||||||
|
@ -115,13 +115,17 @@ where
|
|||||||
// Start the `http_server` service.
|
// Start the `http_server` service.
|
||||||
//
|
//
|
||||||
// Note: presently we are ignoring the config and _always_ starting a HTTP server.
|
// Note: presently we are ignoring the config and _always_ starting a HTTP server.
|
||||||
let http_exit_signal = Some(http_server::start_service(
|
let http_exit_signal = if config.http_conf.enabled {
|
||||||
&config.http_conf,
|
Some(http_server::start_service(
|
||||||
executor,
|
&config.http_conf,
|
||||||
network_send,
|
executor,
|
||||||
beacon_chain.clone(),
|
network_send,
|
||||||
&log,
|
beacon_chain.clone(),
|
||||||
));
|
&log,
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let (slot_timer_exit_signal, exit) = exit_future::signal();
|
let (slot_timer_exit_signal, exit) = exit_future::signal();
|
||||||
if let Ok(Some(duration_to_next_slot)) = beacon_chain.slot_clock.duration_to_next_slot() {
|
if let Ok(Some(duration_to_next_slot)) = beacon_chain.slot_clock.duration_to_next_slot() {
|
||||||
|
@ -15,13 +15,15 @@ use tokio::runtime::TaskExecutor;
|
|||||||
pub struct HttpServerConfig {
|
pub struct HttpServerConfig {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub listen_address: String,
|
pub listen_address: String,
|
||||||
|
pub listen_port: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for HttpServerConfig {
|
impl Default for HttpServerConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
listen_address: "127.0.0.1:5052".to_string(),
|
listen_address: "127.0.0.1".to_string(),
|
||||||
|
listen_port: "5052".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,16 +71,14 @@ pub fn start_service<T: BeaconChainTypes + 'static>(
|
|||||||
// 2. Build an exit future that will shutdown the server when requested.
|
// 2. Build an exit future that will shutdown the server when requested.
|
||||||
// 3. Return the exit future, so the caller may shutdown the service when desired.
|
// 3. Return the exit future, so the caller may shutdown the service when desired.
|
||||||
let http_service = {
|
let http_service = {
|
||||||
|
let listen_address = format!("{}:{}", config.listen_address, config.listen_port);
|
||||||
// Start the HTTP server
|
// Start the HTTP server
|
||||||
let server_start_result = iron.http(config.listen_address.clone());
|
let server_start_result = iron.http(listen_address.clone());
|
||||||
|
|
||||||
if server_start_result.is_ok() {
|
if server_start_result.is_ok() {
|
||||||
info!(log, "HTTP server running on {}", config.listen_address);
|
info!(log, "HTTP server running on {}", listen_address);
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(log, "HTTP server failed to start on {}", listen_address);
|
||||||
log,
|
|
||||||
"HTTP server failed to start on {}", config.listen_address
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a future that will shutdown the HTTP server when the `shutdown_trigger` is
|
// Build a future that will shutdown the HTTP server when the `shutdown_trigger` is
|
||||||
|
@ -68,6 +68,28 @@ fn main() {
|
|||||||
.help("Listen port for RPC endpoint.")
|
.help("Listen port for RPC endpoint.")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
|
// HTTP related arguments
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("http")
|
||||||
|
.long("http")
|
||||||
|
.value_name("HTTP")
|
||||||
|
.help("Enable the HTTP server.")
|
||||||
|
.takes_value(false),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("http-address")
|
||||||
|
.long("http-address")
|
||||||
|
.value_name("HTTPADDRESS")
|
||||||
|
.help("Listen address for the HTTP server.")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("http-port")
|
||||||
|
.long("http-port")
|
||||||
|
.value_name("HTTPPORT")
|
||||||
|
.help("Listen port for the HTTP server.")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("db")
|
Arg::with_name("db")
|
||||||
.long("db")
|
.long("db")
|
||||||
|
Loading…
Reference in New Issue
Block a user