From bfa8b3b3c8ec5d87913f6216b748d61e9369ad14 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 20 Jan 2025 16:29:52 +0100 Subject: [PATCH] BREAKING CHANGE: Change default serve port to 3000 and add ability to override (#265) * Change default serve port to 3000 and add ability to override * Fix documentation comment * Only change the webhost url if not running in a container * Refactor and simplify * Always use default port --- README.md | 6 +++--- docs/source/contribute/locally.md | 10 +++++----- src/docs-builder/Cli/Commands.cs | 8 ++++---- src/docs-builder/Http/DocumentationWebHost.cs | 5 ++++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b8be97d4..8707fc68 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Options: Commands: generate Converts a source markdown folder or file to an output folder - serve Continuously serve a documentation folder at http://localhost:5000. + serve Continuously serve a documentation folder at http://localhost:3000. File systems changes will be reflected without having to restart the server. ``` @@ -63,10 +63,10 @@ Through the `serve` command you can continuously and partially compile your docu ```bash docker run -v "./.git:/app/.git" -v "./docs:/app/docs" -v "./.artifacts:/app/.artifacts" \ - -p 8080:8080 ghcr.io/elastic/docs-builder:edge serve + -p 3000:3000 ghcr.io/elastic/docs-builder:edge serve ``` -Each page is compiled on demand as you browse http://localhost:8080 and is never cached so changes to files and +Each page is compiled on demand as you browse http://localhost:3000 and is never cached so changes to files and navigation will always be reflected upon refresh. Note the docker image is `linux-x86` and will be somewhat slower to invoke on OSX due to virtualization. diff --git a/docs/source/contribute/locally.md b/docs/source/contribute/locally.md index 5784b7e7..7818afbe 100644 --- a/docs/source/contribute/locally.md +++ b/docs/source/contribute/locally.md @@ -27,7 +27,7 @@ Follow these steps to contribute to Elastic docs. ``` 3. **Run the Binary:** - Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the docset.yml file that you want to build can be specified with `-p`: + Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the docset.yml file that you want to build can be specified with `-p`: ```sh ./docs-builder serve -p ./path/to/docs ``` @@ -51,7 +51,7 @@ Follow these steps to contribute to Elastic docs. ``` 3. **Run the Binary:** - Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the docset.yml file that you want to build can be specified with `-p`: + Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the docset.yml file that you want to build can be specified with `-p`: ```sh .\docs-builder serve -p ./path/to/docs ``` @@ -75,7 +75,7 @@ Follow these steps to contribute to Elastic docs. ``` 3. **Run the Binary:** - Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the docset.yml file that you want to build can be specified with `-p`: + Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the docset.yml file that you want to build can be specified with `-p`: ```sh ./docs-builder serve -p ./path/to/docs ``` @@ -99,7 +99,7 @@ git clone https://github.com/elastic/docs-content.git ``` 2. **Run the Binary:** - Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the `docset.yml` file that you want to build can be specified with `-p`: + Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`: ```sh # macOS/Linux ./docs-builder serve -p ./migration-test @@ -108,7 +108,7 @@ git clone https://github.com/elastic/docs-content.git .\docs-builder serve -p .\migration-test ``` -Now you should be able to view the documentation locally by navigating to http://localhost:5000. +Now you should be able to view the documentation locally by navigating to http://localhost:3000. ## Step 4: Open a PR [#step-four] diff --git a/src/docs-builder/Cli/Commands.cs b/src/docs-builder/Cli/Commands.cs index d9de0d02..d7b9ecc3 100644 --- a/src/docs-builder/Cli/Commands.cs +++ b/src/docs-builder/Cli/Commands.cs @@ -16,20 +16,20 @@ namespace Documentation.Builder.Cli; internal class Commands(ILoggerFactory logger, ICoreService githubActionsService) { /// - /// Continuously serve a documentation folder at http://localhost:5000. + /// Continuously serve a documentation folder at http://localhost:3000. /// File systems changes will be reflected without having to restart the server. /// /// -p, Path to serve the documentation. /// Defaults to the`{pwd}/docs` folder /// + /// Port to serve the documentation. /// [Command("serve")] - public async Task Serve(string? path = null, Cancel ctx = default) + public async Task Serve(string? path = null, int port = 3000, Cancel ctx = default) { - var host = new DocumentationWebHost(path, logger, new FileSystem()); + var host = new DocumentationWebHost(path, port, logger, new FileSystem()); await host.RunAsync(ctx); await host.StopAsync(ctx); - } /// diff --git a/src/docs-builder/Http/DocumentationWebHost.cs b/src/docs-builder/Http/DocumentationWebHost.cs index 9e780394..82549bbf 100644 --- a/src/docs-builder/Http/DocumentationWebHost.cs +++ b/src/docs-builder/Http/DocumentationWebHost.cs @@ -10,6 +10,7 @@ using Elastic.Markdown.Diagnostics; using Elastic.Markdown.IO; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -28,7 +29,7 @@ public class DocumentationWebHost private readonly BuildContext _context; - public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fileSystem) + public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFileSystem fileSystem) { var builder = WebApplication.CreateSlimBuilder(); @@ -54,6 +55,8 @@ public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fil //builder.Services.AddSingleton(logger); + builder.WebHost.UseUrls($"http://localhost:{port}"); + _webApplication = builder.Build(); SetUpRoutes(); }