forked from FreakU/watch-party
Support HOST and PORT environment variables for socket binding
This commit is contained in:
parent
16cd0a45fd
commit
9e49ed1820
|
@ -6,5 +6,6 @@ A Rust HTTP service that allows you to watch videos together with friends.
|
|||
|
||||
```shell
|
||||
$ cargo run --release
|
||||
# The server should listen at http://127.0.0.1:3000/ by default
|
||||
# The server should listen at http://127.0.0.1:3000/ by default,
|
||||
# but you can use the HOST and PORT environment variables to override this
|
||||
```
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, sync::Mutex};
|
||||
use std::{collections::HashMap, net::IpAddr, sync::Mutex};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use serde_json::json;
|
||||
|
@ -136,5 +136,13 @@ async fn main() {
|
|||
.or(warb::path::end().and(warb::fs::file("frontend/index.html")))
|
||||
.or(warb::fs::dir("frontend"));
|
||||
|
||||
warb::serve(routes).run(([127, 0, 0, 1], 3000)).await;
|
||||
let host = std::env::var("HOST")
|
||||
.ok()
|
||||
.and_then(|s| s.parse::<IpAddr>().ok())
|
||||
.unwrap_or_else(|| [127, 0, 0, 1].into());
|
||||
let port = std::env::var("PORT")
|
||||
.ok()
|
||||
.and_then(|s| s.parse::<u16>().ok())
|
||||
.unwrap_or(3000);
|
||||
warb::serve(routes).run((host, port)).await;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue