fix(serve): honour the configured base path locally - #1
Open
burinc wants to merge 3 commits into
Open
Conversation
generate! bakes :base-path into every emitted URL, but serve! was a plain static handler rooted at output-dir. A project with a base path therefore previewed as an unstyled page with every link dead: the homepage resolved at /, while the CSS and every nav link it pointed at 404'd under the prefix. serve! now strips the base path before resolving against output-dir, so local preview matches what deploys. Root-hosted projects, where the base path is the empty string, are unaffected.
The README told readers that bb serve ignores :base-path and that a base-pathed site would 404 its own assets locally, with a manual workaround: copy the build into a directory named after the base path and serve its parent. serve! now mounts the build at the configured base path, so the workaround is unnecessary and the caveat is no longer true.
strip-base-path requires uri to be exactly base, or base followed by "/". That was the only branch of the cond with no test, and the docstring's claim about siblings rested on it. The input matters more than it looks. Most near-misses are masked by the (subs rel 1) on the next line, which assumes a leading slash: "/x-other" strips to "-other", loses its first character, and 404s under a broken guard too, so it discriminates nothing. "/x_index.html" is the shape that leaks: it strips to "_index.html", the subs drops the underscore, and the handler serves the real homepage at a uri that is not under the base path at all. Verified by breaking the guard: the test fails with 200 where 404 was expected, and passes again once restored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
generate!bakes:base-pathinto every emitted URL, butserve!was a plain static handler rooted atoutput-dirthat knew nothing about it. A project with a base path therefore previewed as an unstyled page with every link dead: the homepage resolved at/, while the CSS and every nav link it pointed at 404'd under the prefix.The README already documented this, with a manual workaround:
This makes the workaround unnecessary and removes the caveat.
What changed
serve!normalizes:base-paththrough the existingbase-pathfn and passes it tomake-static-handler, which strips that prefix from each request before resolving againstoutput-dir, treating the bare base path as the homepage. An empty base path is a no-op, so root-hosted projects are unaffected. The startup line now prints the full URL including the prefix.Measured against a real project
Before, on a project configured with
:base-path "/mcp-tkx":After:
raygui-jltpreviews the same broken way onmaintoday, for the same reason.Tests
Two added, covering both directions, because fixing one configuration by breaking the other is the obvious risk here:
static-handler-serves-under-the-configured-base-path: a prefixed request resolves, the bare base path serves the homepage, and the unprefixed path is not found.static-handler-is-unaffected-when-root-hosted: with an empty base path,/index.htmland/still serve.Suite goes from 67 tests / 147 assertions to 69 / 152, 0 failures.