Avoid panics when binding addresses
This commit is contained in:
parent
41e436f331
commit
366e5c426f
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## 0.12.1 (unreleased)
|
## 0.12.1 (unreleased)
|
||||||
|
|
||||||
- Add line
|
- Add line highlighting in code blocks
|
||||||
- Fix the new `zola serve` being broken on Windows
|
- Fix the new `zola serve` being broken on Windows
|
||||||
- Fix slugified taxonomies not being rendered at the right path
|
- Fix slugified taxonomies not being rendered at the right path
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,12 @@ fn create_new_site(
|
||||||
|
|
||||||
let base_address = format!("{}:{}", base_url, interface_port);
|
let base_address = format!("{}:{}", base_url, interface_port);
|
||||||
let address = format!("{}:{}", interface, interface_port);
|
let address = format!("{}:{}", interface, interface_port);
|
||||||
|
|
||||||
|
// Stop right there if we can't bind to the address
|
||||||
|
if Server::try_bind(&address.parse().unwrap()).is_err() {
|
||||||
|
return Err(format!("Cannot start server on address {}.", address))?;
|
||||||
|
}
|
||||||
|
|
||||||
let base_url = if site.config.base_url.ends_with('/') {
|
let base_url = if site.config.base_url.ends_with('/') {
|
||||||
format!("http://{}/", base_address)
|
format!("http://{}/", base_address)
|
||||||
} else {
|
} else {
|
||||||
|
@ -331,7 +337,7 @@ pub fn serve(
|
||||||
|
|
||||||
let ws_server = ws_server
|
let ws_server = ws_server
|
||||||
.bind(&*ws_address)
|
.bind(&*ws_address)
|
||||||
.map_err(|_| format!("Address {} is already in use.", &ws_address))?;
|
.map_err(|_| format!("Cannot bind to address {} for the websocket server. Maybe the port is already in use?", &ws_address))?;
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
ws_server.run().unwrap();
|
ws_server.run().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue