Handle failure to bind
This commit is contained in:
parent
8b30a7241d
commit
efddac5e95
|
@ -1,5 +1,6 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
use tiny_http::Header;
|
use tiny_http::Header;
|
||||||
use tiny_http::Request;
|
use tiny_http::Request;
|
||||||
|
@ -12,7 +13,13 @@ use tiny_http::StatusCode;
|
||||||
/// Runs the server in a single thread, bound to 0.0.0.0 on the provided port. Requests are
|
/// Runs the server in a single thread, bound to 0.0.0.0 on the provided port. Requests are
|
||||||
/// handled first-come, first-serve
|
/// handled first-come, first-serve
|
||||||
pub fn go(domains: &[&str], port: u16) {
|
pub fn go(domains: &[&str], port: u16) {
|
||||||
let server = Server::http(("0.0.0.0", port)).unwrap();
|
let server = match Server::http(("0.0.0.0", port)) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Couldn't create server on 0.0.0.0:{port}\n{e}");
|
||||||
|
exit(1004);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
println!("Running on 0.0.0.0:{port}");
|
println!("Running on 0.0.0.0:{port}");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue