Skip to content

Commit 4aae4e6

Browse files
RobWaltKeats
authored andcommitted
feat: support better port 0 user facing messages (#2859)
If a user chooses to use port 0, then the operating system will choose one of the available ports automatically. This is very useful in cases where you want to allow a `zola serve` for a broader user base which might already bind a subset of their ports and if you don't know which ones they might use. This feature was already supported by zola, however, the printed output just printed port 0 and didn't report which port the operating system actually chose. Example output of `zola serve -p 0` before the change ``` Web server is available at http://127.0.0.1:0 (bound to 127.0.0.1:0) ``` Example output of `zola serve -p 0` after the change ``` Web server is available at http://127.0.0.1:37327 (bound to 127.0.0.1:37327) ```
1 parent 69fa897 commit 4aae4e6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/cmd/serve.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ pub fn serve(
543543

544544
println!(
545545
"Web server is available at {} (bound to {})\n",
546-
&constructed_base_url, &bind_address
546+
&constructed_base_url
547+
.replace(&bind_address.to_string(), &server.local_addr().to_string()),
548+
&server.local_addr()
547549
);
548550
if open {
549551
if let Err(err) = open::that(&constructed_base_url) {

0 commit comments

Comments
 (0)