1
0
mirror of https://github.com/spikecodes/libreddit synced 2024-12-25 18:15:16 +01:00

Add Address Command-line Argument

This commit is contained in:
spikecodes 2020-11-22 19:21:07 -08:00
parent 1a33582966
commit 16bf825e14
3 changed files with 26 additions and 11 deletions

View File

@ -40,7 +40,6 @@ Think Invidious but for Reddit. Watch your cat videos without being watched.
- [ ] Proxied images
- [x] Reddit-hosted video
- [ ] Proxied video
- [ ] Localized post date
- [x] Users
- [x] Username
- [x] Karma
@ -62,6 +61,17 @@ Think Invidious but for Reddit. Watch your cat videos without being watched.
## Deploy an Instance
Once installed, deploy Libreddit (unless you're using Docker) by running:
```
libreddit
```
Specify a custom address for the server by passing the `-a` or `--address` argument:
```
libreddit --address=0.0.0.0:8111
```
### A) Cargo
Make sure Rust stable is installed along with `cargo`, Rust's package manager.
@ -91,11 +101,6 @@ Install:
yay -S libreddit-git
```
Deploy:
```
libreddit
```
## Building
```

View File

@ -1,23 +1,23 @@
// Import Crates
use actix_web::{get, App, HttpResponse, HttpServer};
use std::fs;
// Reference local files
mod popular;
mod post;
mod subreddit;
mod user;
mod proxy;
// Create Services
#[get("/style.css")]
async fn style() -> HttpResponse {
let file = fs::read_to_string("static/style.css").expect("ERROR: Could not read style.css");
let file = std::fs::read_to_string("static/style.css").expect("ERROR: Could not read style.css");
HttpResponse::Ok().content_type("text/css").body(file)
}
#[get("/robots.txt")]
async fn robots() -> HttpResponse {
let file = fs::read_to_string("static/robots.txt").expect("ERROR: Could not read robots.txt");
let file = std::fs::read_to_string("static/robots.txt").expect("ERROR: Could not read robots.txt");
HttpResponse::Ok().body(file)
}
@ -28,8 +28,18 @@ async fn favicon() -> HttpResponse {
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let args: Vec<String> = std::env::args().collect();
let mut address = "0.0.0.0:8080".to_string();
if args.len() > 1 {
if args[1].starts_with("--address=") || args[1].starts_with("-a=") {
let split: Vec<&str> = args[1].split("=").collect();
address = split[1].to_string();
}
}
// start http server
println!("Running Libreddit on 0.0.0.0:8080!");
println!("Running Libreddit on {}!", address);
HttpServer::new(|| {
App::new()
@ -47,7 +57,7 @@ async fn main() -> std::io::Result<()> {
// USER SERVICES
.service(user::page)
})
.bind("0.0.0.0:8080")?
.bind(address)?
.run()
.await
}

0
src/proxy.rs Normal file
View File