mirror of
https://github.com/redlib-org/redlib.git
synced 2025-04-20 22:09:14 +00:00
feat: add environment variables and dedicated flags for ipv4/6 only
This commit is contained in:
parent
5ef57812f8
commit
0d478d587f
1 changed files with 24 additions and 1 deletions
25
src/main.rs
25
src/main.rs
|
@ -107,6 +107,20 @@ async fn main() {
|
||||||
let matches = Command::new("Redlib")
|
let matches = Command::new("Redlib")
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about("Private front-end for Reddit written in Rust ")
|
.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(
|
||||||
Arg::new("redirect-https")
|
Arg::new("redirect-https")
|
||||||
.short('r')
|
.short('r')
|
||||||
|
@ -149,7 +163,16 @@ async fn main() {
|
||||||
let port = matches.get_one::<String>("port").unwrap();
|
let port = matches.get_one::<String>("port").unwrap();
|
||||||
let hsts = matches.get_one("hsts").map(|m: &String| m.as_str());
|
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...");
|
println!("Starting Redlib...");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue