Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add environment variables and dedicated flags for ipv4/6 only #307

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ async fn main() {
let matches = Command::new("Redlib")
.version(env!("CARGO_PKG_VERSION"))
.about("Private front-end for Reddit written in Rust ")
.arg(
Arg::new("ipv4-only")
.short('4')
.long("ipv4-only")
.help("Listen on IPv4 only")
.num_args(0),
)
.arg(
Arg::new("ipv6-only")
.short('6')
.long("ipv6-only")
.help("Listen on IPv6 only")
.num_args(0),
)
.arg(
Arg::new("redirect-https")
.short('r')
Expand Down Expand Up @@ -149,7 +163,16 @@ async fn main() {
let port = matches.get_one::<String>("port").unwrap();
let hsts = matches.get_one("hsts").map(|m: &String| m.as_str());

let listener = [address, ":", port].concat();
let ipv4_only = std::env::var("IPV4_ONLY").is_ok() || matches.get_flag("ipv4-only");
let ipv6_only = std::env::var("IPV6_ONLY").is_ok() || matches.get_flag("ipv6-only");

let listener = if ipv4_only {
format!("0.0.0.0:{}", port)
} else if ipv6_only {
format!("[::]:{}", port)
} else {
[address, ":", port].concat()
};

println!("Starting Redlib...");

Expand Down
Loading