Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with trailing slashes in the base #234

Merged
merged 8 commits into from
Oct 16, 2021

Conversation

j-maas
Copy link
Contributor

@j-maas j-maas commented Oct 2, 2021

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 open localhost:1234/sub/ but not localhost:1234/sub. This PR changes the basepath-middleware.js's check to make the trailing slash optional, and make localhost: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 running elm-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.

@j-maas j-maas marked this pull request as draft October 2, 2021 15:14
@j-maas j-maas marked this pull request as ready for review October 2, 2021 15:26
@j-maas
Copy link
Contributor Author

j-maas commented Oct 2, 2021

The build failures are from elm-review. Since I didn't touch any .elm files, I suspect that these build errors are not caused by the changes in this PR.

@dillonkearns dillonkearns merged commit e1e2fab into dillonkearns:master Oct 16, 2021
@j-maas j-maas deleted the fix-base-trailing-slash branch October 17, 2021 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elm-pages build --base sub does not render correctly
2 participants