Add "port" command line argument

This commit is contained in:
spikecodes 2021-02-18 11:49:50 -08:00
parent 3652342f46
commit 8560e8a37a
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
3 changed files with 18 additions and 10 deletions

View File

@ -193,7 +193,8 @@ libreddit
| Short | Long | Example |
|-------|--------------------|-----------------------------------|
| `-a` | `--address` | `libreddit --adress=0.0.0.0:8111` |
| `-a` | `--address` | `libreddit --adress=0.0.0.0` |
| `-p` | `--port` | `libreddit --port=3030` |
| `-r` | `--redirect-https` | `libreddit --redirect-https` |
## Building

View File

@ -111,7 +111,16 @@ async fn main() -> tide::Result<()> {
.long("address")
.value_name("ADDRESS")
.help("Sets address to listen on")
.default_value("0.0.0.0:8080")
.default_value("0.0.0.0")
.takes_value(true),
)
.arg(
Arg::with_name("port")
.short("p")
.long("port")
.value_name("PORT")
.help("Port to listen on")
.default_value("8080")
.takes_value(true),
)
.arg(
@ -123,13 +132,14 @@ async fn main() -> tide::Result<()> {
)
.get_matches();
let address = matches.value_of("address").unwrap_or("0.0.0.0:8080");
let address = matches.value_of("address").unwrap_or("0.0.0.0");
let port = matches.value_of("port").unwrap_or("8080");
let force_https = matches.is_present("redirect-https");
dbg!(&force_https);
let listener = format!("{}:{}", address, port);
// Start HTTP server
println!("Running Libreddit v{} on {}!", env!("CARGO_PKG_VERSION"), &address);
println!("Running Libreddit v{} on {}!", env!("CARGO_PKG_VERSION"), &listener);
let mut app = tide::new();
@ -224,6 +234,6 @@ async fn main() -> tide::Result<()> {
// Default service in case no routes match
app.at("*").get(|_| error("Nothing here".to_string()));
app.listen(address).await?;
app.listen(listener).await?;
Ok(())
}

View File

@ -194,10 +194,7 @@ pub fn format_url(url: &str) -> String {
match re.captures(url) {
Some(caps) => format!("/vid/{}/{}", &caps[1], &caps[2]),
None => {
dbg!(url);
String::new()
}
None => String::new()
}
}
_ => format!("/proxy/{}/", encode(url).as_str()),