Skip to content

Commit

Permalink
feat(config): listen addr & port (#15)
Browse files Browse the repository at this point in the history
* feat(config): listen addr & port config

* chore: lint

* safe default
  • Loading branch information
Savid authored May 4, 2023
1 parent 3cd7cc2 commit 32492a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use clap::{builder::PossibleValue, Parser, ValueEnum};
use eth2_network_config::Eth2NetworkConfig;
use std::net::IpAddr;
use std::str::FromStr;
use strum::{EnumString, IntoStaticStr};

#[derive(Debug, Clone, Parser)]
#[command(about = "Ethereum execution engine multiplexer")]
pub struct Config {
/// Listening address for the HTTP server.
#[arg(long, value_name = "IP", default_value = "127.0.0.1")]
pub listen_address: IpAddr,
/// Listening port for the HTTP server.
#[arg(long, value_name = "PORT", default_value = "8552")]
pub listen_port: u16,
/// Primary execution engine to be shared by connected consensus nodes.
#[arg(long, value_name = "URL", default_value = "http://localhost:8551")]
pub ee_url: String,
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use crate::{
};
use axum::{
extract::{rejection::JsonRejection, DefaultBodyLimit, State},
http::StatusCode,
response::IntoResponse,
routing::{get, post},
Json, Router, http::StatusCode,
Json, Router,
};
use clap::Parser;
use eth2::types::MainnetEthSpec;
Expand Down Expand Up @@ -52,6 +53,8 @@ async fn main() {
let config = Config::parse();

let body_limit_mb = config.body_limit_mb;
let listen_address = config.listen_address;
let listen_port = config.listen_port;
let multiplexer = Arc::new(Multiplexer::<E>::new(config, executor, log).unwrap());

let app = Router::new()
Expand All @@ -61,7 +64,7 @@ async fn main() {
.with_state(multiplexer)
.layer(DefaultBodyLimit::max(body_limit_mb * MEGABYTE));

let addr = SocketAddr::from(([127, 0, 0, 1], 8552));
let addr = SocketAddr::from((listen_address, listen_port));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
Expand Down

0 comments on commit 32492a1

Please sign in to comment.