mirror of
https://github.com/getzola/zola
synced 2024-11-10 06:14:19 +00:00
Avoid panics when binding addresses
This commit is contained in:
parent
41e436f331
commit
366e5c426f
2 changed files with 8 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
## 0.12.1 (unreleased)
|
||||
|
||||
- Add line
|
||||
- Add line highlighting in code blocks
|
||||
- Fix the new `zola serve` being broken on Windows
|
||||
- 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 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('/') {
|
||||
format!("http://{}/", base_address)
|
||||
} else {
|
||||
|
@ -331,7 +337,7 @@ pub fn serve(
|
|||
|
||||
let ws_server = ws_server
|
||||
.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 || {
|
||||
ws_server.run().unwrap();
|
||||
|
|
Loading…
Reference in a new issue