feat: lightweight HTTP server for Verso projects - #876
Conversation
This replaces Python or Node local servers, with defaults that are better-suited to hosting Verso correctly. It also doesn't rely on users having any other programming language ecosystem available.
…r#900) In writing leanprover#876, @david-christiansen noted "this branch encountered a bug in the TeX code generation that needed fixing" — but I think the issue was slightly misdiagnosed, it wasn't a fragility issue, a `]` anywhere in an item description (including outside of verbatim) caused a rendering issue because it was read as the description closer. This fix fixes the bug from leanprover#876, also fixes bugs for `]` in literal text, and adds a test for the behavior.
| You can preview the resulting files by running | ||
| `python3 -m http.server 8000 -d html` and pointing a web browser to | ||
| http://localhost:8000/ | ||
| You can preview the resulting files by running `lake exe serve html` |
There was a problem hiding this comment.
Let's do lake exe verso-serve for this. (Todo for me: do the cli arguments to verso-serve make sense?)
There was a problem hiding this comment.
(Check that no-args serves .)
robsimmons
left a comment
There was a problem hiding this comment.
Some documentation comments (which imply some code changes too, especially around removing command-line options to avoid duplication). I'm still not sure every configuration option makes sense for a development-only and/or verso-specific server, but that may be a failure of imagination — and these defaults seem reasonable.
| %%% | ||
|
|
||
| Verso includes a small HTTP server for previewing generated HTML on your own machine. | ||
| Run it with `lake exe serve`. |
There was a problem hiding this comment.
Change to verso-serve throughout.
| : `DIR` | ||
|
|
||
| The directory served at `/`, relative to the current directory. Defaults to the current directory. | ||
|
|
There was a problem hiding this comment.
This is confusing without a USAGE-style line that explains that DIR is a positional argument. Maybe just start "in addition to the directory served, which is given as a positional argument, the following arguments are supported:
There was a problem hiding this comment.
I think the new text addresses this
|
|
||
| : `--config FILE` | ||
|
|
||
| Load configuration from `FILE`. Defaults to `./serve.toml` if it exists. |
There was a problem hiding this comment.
| Load configuration from `FILE`. Defaults to `./serve.toml` if it exists. | |
| Load configuration from `FILE`. Defaults to `./serve.toml` if it exists. Otherwise uses defaults (see {ref "serve-config"}[Configuration file specification]). |
There was a problem hiding this comment.
I went with a somewhat more verbose (and grammatical) alternative.
| tag := "serve-config" | ||
| %%% | ||
|
|
||
| For anything beyond serving a single directory, place a `serve.toml` file next to the project, or point at one with `--config`. |
There was a problem hiding this comment.
"Next to the project" assumes verso-serve is being invoked in the folder with lakefile.toml, which isn't necessarily the case.
| For anything beyond serving a single directory, place a `serve.toml` file next to the project, or point at one with `--config`. | |
| For anything beyond serving a single directory, create a `serve.toml` file. When `verso-serve` is invoked, it will look for `serve.toml` in the current working directory unless another location is specified with the `--config` {ref "serve-options"}[command line option]. |
There was a problem hiding this comment.
lake exe only works from the project root, so I think this is actually the right way to do things.
| :::paragraph | ||
| As requests arrive, each is logged with the active port, the method, the path, and the response status: | ||
|
|
||
| ``` | ||
| [8000] GET /index.html 200 | ||
| [8000] GET /missing 404 | ||
| ``` | ||
| ::: | ||
|
|
There was a problem hiding this comment.
I think this would read better without this section — it's behavior description that will be either obvious to the user or still confusing with this explanation; it would be better to get on to the command-line options.
There was a problem hiding this comment.
Agreed - it's gone.
robsimmons
left a comment
There was a problem hiding this comment.
mostly comments on the docs / spec, i didn't review tests but the Config/Mime/Static/VersoServeMain quartet looks okay modulo questions about docs/spec.
| : `banner` | ||
|
|
||
| A line shown in the startup banner to identify the project. Must be a string. No banner is shown by default. |
There was a problem hiding this comment.
This feels like a pretty high documentation-noise to user-value-signal ratio. Was there a use case for a configurable command-line banner you had in mind?
There was a problem hiding this comment.
From conversation with @robsimmons: "banner" was initially understood as HTML injection rather than command-line dump. Be more specific here.
| Scalar flags override the corresponding config values. A positional directory replaces the `/` | ||
| mount. If no `/` mount remains, a default one serving the current directory is added, so `/` is | ||
| always mapped. | ||
| -/ |
There was a problem hiding this comment.
The mount-juggling is strange in a function called withCli, and I think if there are any mounts in the config file then lake exe verso-serve should not auto-mount the root directory — and possibly should reject a positional argument altogether. The port winning on the CLI makes sense, but the mount isn't anywhere near so obvious to me.
If the ServeConfig/CliArgs overlap is limited to mounts and ports this could probably be inlined.
There was a problem hiding this comment.
The positional argument is now rejected when mounts are configured
| You can preview the resulting files by running | ||
| `python3 -m http.server 8000 -d html` and pointing a web browser to | ||
| http://localhost:8000/ | ||
| You can preview the resulting files by running `lake exe serve html` |
Co-authored-by: Robert J. Simmons <442315+robsimmons@users.noreply.github.com>
Co-authored-by: Robert J. Simmons <442315+robsimmons@users.noreply.github.com>
Co-authored-by: Robert J. Simmons <442315+robsimmons@users.noreply.github.com>
# Conflicts: # test-projects/literate-config/lake-manifest.json # test-projects/literate-multi-root/lake-manifest.json
a9a6299 to
e4b21e8
Compare
Adds a lightweight HTTP server for previewing generated Verso HTML locally, run with
lake exe serve. The server binds only 127.0.0.1, reducing the temptation to deploy it to production.This replaces Python or Node local servers, with defaults that are better-suited to hosting Verso correctly. It also doesn't rely on users having any other programming language ecosystem available.
It can be configured from the command line, or for slightly more complex setups, via
serve.toml.Along the way, this branch encountered a bug in the TeX code generation that needed fixing in order to render the docs for the feature.