Allow customizing the listen port and interface
This commit is contained in:
parent
1d7b09f92a
commit
88f13d585a
2 changed files with 17 additions and 2 deletions
|
@ -2,7 +2,7 @@ use async_std::path::PathBuf;
|
|||
use async_std::stream::StreamExt;
|
||||
use axum::extract::State;
|
||||
use axum::{routing::get, Router};
|
||||
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
|
||||
use std::net::SocketAddr;
|
||||
use tokio::task::JoinSet;
|
||||
|
||||
mod dokku;
|
||||
|
@ -64,7 +64,7 @@ async fn main() {
|
|||
|
||||
let app = Router::new().route("/hosts", get(hosts)).with_state(state);
|
||||
|
||||
let addr = &SocketAddr::new(IpAddr::from(Ipv6Addr::UNSPECIFIED), 3000);
|
||||
let addr = &SocketAddr::new(utils::get_bind_host(), utils::get_port());
|
||||
println!("Listening on {addr}");
|
||||
axum::Server::bind(addr)
|
||||
.serve(app.into_make_service())
|
||||
|
|
15
src/utils.rs
15
src/utils.rs
|
@ -1,4 +1,5 @@
|
|||
use std::ffi::OsString;
|
||||
use std::net::{IpAddr, Ipv6Addr};
|
||||
|
||||
#[inline]
|
||||
pub fn osstring_starts_with(data: OsString, prefix: char) -> bool {
|
||||
|
@ -7,3 +8,17 @@ pub fn osstring_starts_with(data: OsString, prefix: char) -> bool {
|
|||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_port() -> u16 {
|
||||
match std::env::var("PORT").ok() {
|
||||
Some(s) => s.parse().unwrap(),
|
||||
None => 3000,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_bind_host() -> IpAddr {
|
||||
match std::env::var("BIND").ok() {
|
||||
Some(s) => s.parse().unwrap(),
|
||||
None => IpAddr::V6(Ipv6Addr::UNSPECIFIED),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue