Skip to content

Cannot use serve --open with --port 0 #2599

Open
@koalp

Description

@koalp

Problem

When using the mdbook serve command with --port 0 and --open options, the opened page is wrong, as the port is 0 instead of the random port attributed by the system.

Image

Steps

  1. mdbook init abc --force
  2. mdbook serve abc --port 0 --open

Possible Solution(s)

The serving_url should contain the bound port instead of the asked port (0)

let serving_url = format!("http://{address}");

Maybe using something like bind_ephemeral could be used. It would maybe require to move the creation of the warp server in a separate function run before the thread spawn.

mdBook/src/cmd/serve.rs

Lines 88 to 90 in 3a8faba

let thread_handle = std::thread::spawn(move || {
serve(build_dir, sockaddr, reload_tx, &file_404);
});

Notes

No response

Version

mdbook v0.4.47

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: A bug, incorrect or unintended behaviorCommand-serveCommand: serve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions