Skip to content

Commit

Permalink
feat: add environment variables and dedicated flags for ipv4/6 only (#…
Browse files Browse the repository at this point in the history
…307)

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

* fix(readme): mention all flags on README
  • Loading branch information
sigaloid authored Feb 3, 2025
1 parent 96ad7bf commit 23cda23
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 24 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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...");

Expand Down

0 comments on commit 23cda23

Please sign in to comment.