Skip to content

Commit

Permalink
Take endpoint root address from environment variable
Browse files Browse the repository at this point in the history
Signed-off-by: nain-F49FF806 <126972030+nain-F49FF806@users.noreply.github.com>
  • Loading branch information
nain-F49FF806 committed Sep 13, 2023
1 parent ffaca08 commit aadf0d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
29 changes: 24 additions & 5 deletions mediator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
use log::info;

#[tokio::main]
async fn main() {
println!("Hello, world!");
let app_router = mediator::routes::build_router().await;
axum::Server::bind(&"0.0.0.0:8005".parse().unwrap())
.serve(app_router.into_make_service())
.await
.unwrap();
load_dot_env();
setup_logging();
let endpoint_root = std::env::var("ENDPOINT_ROOT").unwrap_or("0.0.0.0:8005".into());
info!("Endpoint root address {}", endpoint_root);
let app_router = mediator::routes::build_router(&endpoint_root).await;
axum::Server::bind(
&endpoint_root
.parse()
.expect("Pass an address to listen on like IP:PORT"),
)
.serve(app_router.into_make_service())
.await
.unwrap();
}

fn setup_logging() {
let env = env_logger::Env::default().default_filter_or("info");
env_logger::init_from_env(env);
}

fn load_dot_env() {
let _ = dotenvy::dotenv();
}
4 changes: 2 additions & 2 deletions mediator/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub async fn oob_invite_qr(State(agent): State<Arc<Agent<IndySdkWallet>>>) -> Ht
))
}

pub async fn build_router() -> Router {
pub async fn build_router(endpoint_root: &str) -> Router {
let mut agent = Agent::new_demo_agent().await.unwrap();
agent
.init_service(vec![], "http://localhost:8005".parse().unwrap())
.init_service(vec![], format!("http://{endpoint_root}").parse().unwrap())
.await
.unwrap();
Router::default()
Expand Down

0 comments on commit aadf0d5

Please sign in to comment.