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

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

* fix(readme): mention all flags on README
This commit is contained in:
Matthew Esposito 2025-02-02 23:30:33 -05:00 committed by GitHub
parent 96ad7bf163
commit 23cda23d01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View file

@ -404,6 +404,17 @@ REDLIB_DEFAULT_USE_HLS = "on"
>
> If using Docker Compose, no changes are needed as the `.env` file is already referenced in `compose.yaml` via the `env_file: .env` line.
## Command Line Flags
Redlib supports the following command line flags:
- `-4`, `--ipv4-only`: Listen on IPv4 only.
- `-6`, `--ipv6-only`: Listen on IPv6 only.
- `-r`, `--redirect-https`: Redirect all HTTP requests to HTTPS (no longer functional).
- `-a`, `--address <ADDRESS>`: Sets address to listen on. Default is `[::]`.
- `-p`, `--port <PORT>`: Port to listen on. Default is `8080`.
- `-H`, `--hsts <EXPIRE_TIME>`: HSTS header to tell browsers that this site should only be accessed over HTTPS. Default is `604800`.
## Instance settings
Assign a default value for each instance-specific setting by passing environment variables to Redlib in the format `REDLIB_{X}`. Replace `{X}` with the setting name (see list below) in capital letters.

View file

@ -108,6 +108,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')
@ -164,7 +178,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...");