Skip to content

Commit 65e451d

Browse files
Add --root option to fsdocs watch for remote/proxy hosting
Closes #924 Previously fsdocs watch always forced root = http://localhost:<port>/, ignoring any user-supplied root parameter. This makes the generated pages unusable when served via GitHub Codespaces port-forwarding, a reverse proxy, or any other non-localhost environment. This PR adds: - A --root option to WatchCommand exposing a user-specified root URL override - An abstract root_override_option on CoreBuildOptions (default None) - Modified watch-mode root logic: uses the --root value when provided, otherwise falls back to http://localhost:<port>/ as before Usage: fsdocs watch --root / # root-relative URLs fsdocs watch --root https://example.com/docs/ # absolute remote URL Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a7b9e55 commit 65e451d

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
### Added
6+
* Add `--root` option to `fsdocs watch` to override the root URL for generated pages. Useful for serving docs via GitHub Codespaces, reverse proxies, or other remote hosting where `localhost` URLs are inaccessible. E.g. `fsdocs watch --root /` or `fsdocs watch --root https://example.com/docs/`. When not set, defaults to `http://localhost:<port>/` as before. [#924](https://github.com/fsprojects/FSharp.Formatting/issues/924)
67
* Add `dotnet fsdocs convert` command to convert a single `.md`, `.fsx`, or `.ipynb` file to HTML (or another output format) without building a full documentation site. [#811](https://github.com/fsprojects/FSharp.Formatting/issues/811)
78
* `fsdocs convert` now accepts the input file as a positional argument (e.g. `fsdocs convert notebook.ipynb -o notebook.html`). [#1019](https://github.com/fsprojects/FSharp.Formatting/pull/1019)
89
* `fsdocs convert` infers the output format from the output file extension when `--outputformat` is not specified (e.g. `-o out.md` implies `--outputformat markdown`). [#1019](https://github.com/fsprojects/FSharp.Formatting/pull/1019)

src/fsdocs-tool/BuildCommand.fs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,9 +1560,15 @@ type CoreBuildOptions(watch) =
15601560
// Adjust the user substitutions for 'watch' mode root
15611561
let userRoot, userParameters =
15621562
if watch then
1563-
let userRoot = sprintf "http://localhost:%d/" this.port_option
1564-
1565-
if userParametersDict.ContainsKey(ParamKeys.root) then
1563+
let userRoot =
1564+
match this.root_override_option with
1565+
| Some r -> r
1566+
| None -> sprintf "http://localhost:%d/" this.port_option
1567+
1568+
if
1569+
userParametersDict.ContainsKey(ParamKeys.root)
1570+
&& this.root_override_option.IsNone
1571+
then
15661572
printfn "ignoring user-specified root since in watch mode, root = %s" userRoot
15671573

15681574
let userParameters =
@@ -2325,6 +2331,9 @@ type CoreBuildOptions(watch) =
23252331
abstract port_option: int
23262332
default x.port_option = 0
23272333

2334+
abstract root_override_option: string option
2335+
default x.root_override_option = None
2336+
23282337
[<Verb("convert",
23292338
HelpText =
23302339
"convert a single document (.md, .fsx, .ipynb) to HTML or another output format without building a full documentation site")>]
@@ -2504,3 +2513,12 @@ type WatchCommand() =
25042513

25052514
[<Option("port", Required = false, Default = 8901, HelpText = "Port to serve content for http://localhost serving.")>]
25062515
member val port = 8901 with get, set
2516+
2517+
override x.root_override_option = if x.root = "" then None else Some x.root
2518+
2519+
[<Option("root",
2520+
Required = false,
2521+
Default = "",
2522+
HelpText =
2523+
"Override the root URL for generated pages. Useful for reverse proxies or GitHub Codespaces. E.g. --root / or --root https://example.com/docs/. When not set, defaults to http://localhost:<port>/.")>]
2524+
member val root = "" with get, set

0 commit comments

Comments
 (0)