Add "port" command line argument
This commit is contained in:
parent
3652342f46
commit
8560e8a37a
@ -193,7 +193,8 @@ libreddit
|
|||||||
|
|
||||||
| Short | Long | Example |
|
| 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` |
|
| `-r` | `--redirect-https` | `libreddit --redirect-https` |
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
20
src/main.rs
20
src/main.rs
@ -111,7 +111,16 @@ async fn main() -> tide::Result<()> {
|
|||||||
.long("address")
|
.long("address")
|
||||||
.value_name("ADDRESS")
|
.value_name("ADDRESS")
|
||||||
.help("Sets address to listen on")
|
.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),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@ -123,13 +132,14 @@ async fn main() -> tide::Result<()> {
|
|||||||
)
|
)
|
||||||
.get_matches();
|
.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");
|
let force_https = matches.is_present("redirect-https");
|
||||||
|
|
||||||
dbg!(&force_https);
|
let listener = format!("{}:{}", address, port);
|
||||||
|
|
||||||
// Start HTTP server
|
// 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();
|
let mut app = tide::new();
|
||||||
|
|
||||||
@ -224,6 +234,6 @@ async fn main() -> tide::Result<()> {
|
|||||||
// Default service in case no routes match
|
// Default service in case no routes match
|
||||||
app.at("*").get(|_| error("Nothing here".to_string()));
|
app.at("*").get(|_| error("Nothing here".to_string()));
|
||||||
|
|
||||||
app.listen(address).await?;
|
app.listen(listener).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -194,10 +194,7 @@ pub fn format_url(url: &str) -> String {
|
|||||||
|
|
||||||
match re.captures(url) {
|
match re.captures(url) {
|
||||||
Some(caps) => format!("/vid/{}/{}", &caps[1], &caps[2]),
|
Some(caps) => format!("/vid/{}/{}", &caps[1], &caps[2]),
|
||||||
None => {
|
None => String::new()
|
||||||
dbg!(url);
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => format!("/proxy/{}/", encode(url).as_str()),
|
_ => format!("/proxy/{}/", encode(url).as_str()),
|
||||||
|
Loading…
Reference in New Issue
Block a user