Add ability to bind to a port

This commit is contained in:
Emi Simpson 2022-02-06 18:22:25 -05:00
parent fbe85fada7
commit 5dd59810b1
Signed by: Emi
GPG key ID: 45E9C6E81BD86E7C
3 changed files with 8 additions and 4 deletions

View file

@ -59,7 +59,7 @@ faery-ring /path/to/domains.txt
docker run -v /path/to/domains.txt:/domains.txt -p 3243:3243 alch0emi/faery-ring
```
Right now, Faery Ring always binds to port 3243, but this might change in the future, who knows. Anyway, now you can point your webserver at Faery Ring! The config below is for Caddy, but any webserver that supports reverse proxies will work!
You can also use the `-p <port>` flag to tell faery-ring what port you want to bind on. If you don't, it'll pick port `3243`. Anyway, now you can point your webserver at Faery Ring! The config below is for Caddy, but any webserver that supports reverse proxies will work!
```Caddyfile
your.web.site {

View file

@ -72,7 +72,7 @@ fn main() {
//
// Step 2: Run the server
//
server::go(&domains);
server::go(&domains, args.port);
}
#[derive(argh::FromArgs)]
@ -81,4 +81,8 @@ struct CommandlineArgs {
/// a text file listing all domains in the ring, one per line
#[argh(positional)]
domains: PathBuf,
/// the port to bind to (default: 3243)
#[argh(option, short='p', default="3243")]
port: u16,
}

View file

@ -11,8 +11,8 @@ use tiny_http::StatusCode;
///
/// Runs the server in a single thread, bound to port 3243. Requests are handled
/// first-come, first-serve
pub fn go(domains: &[&str]) {
let server = Server::http("0.0.0.0:3243").unwrap();
pub fn go(domains: &[&str], port: u16) {
let server = Server::http(("0.0.0.0", port)).unwrap();
println!("Running on 0.0.0.0:3243");