Fix issues with trailing slashes in the base #234
Merged
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.
I revisited #208 and realized that I could simplify it. Additionally, this solves the issue where the index page is not rendered correctly (fixes #217).
To summarize, previously when running
elm-pages dev --base sub
, you would be able to openlocalhost:1234/sub/
but notlocalhost:1234/sub
. This PR changes thebasepath-middleware.js
's check to make the trailing slash optional, and makelocalhost:1234/sub
work.For that we also need to remove the slash from the base path when normalizing it in
cli.js
. A side effect of this is that the index page now works when runningelm-pages build --base path
. Previously the page would render, but then its content was an error message that the page was an invalid route (#217). This was probably to due a faulty prefix check: The page's path is determined to be/sub
, but the route probably tries to remove the base/sub/
which is not a prefix of/sub
. Therefore the route is not correctly determined, because the base is kept. By normalizing the base to not have a trailing slash, this prefix check is fixed and when building the site the index page now is rendered correctly.