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: Ensures that rewrite url contains base path #13233

Merged
merged 12 commits into from
Feb 20, 2025

Conversation

joshmkennedy
Copy link
Contributor

@joshmkennedy joshmkennedy commented Feb 12, 2025

This PR fixes #13033

Changes

After the rewrite, the URL will contain the base path and then the new pathname.

The other issue that was brought up was inconsistencies with trailingSlash and when the base was included in the Astro.rewrite call.

Testing

I have added a new fixture and have added tests to the /tests/rewrite.test.js file that test and ensure the Astro.url pathname always contains the base path. This is tested both with and without the trailingSlash, also with the base being included and excluded in argument of Astro.rewrite.

Docs

and fixes edge cases where rewrites were incorrectly 404ing
Copy link

changeset-bot bot commented Feb 12, 2025

🦋 Changeset detected

Latest commit: b55b5f8

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 12, 2025
and fixes edge cases where rewrites were incorrectly 404ing
@joshmkennedy
Copy link
Contributor Author

Not sure if this needs to be split up into 2 PRs, or if this was the best way to test the solution.

Copy link

codspeed-hq bot commented Feb 12, 2025

CodSpeed Performance Report

Merging #13233 will not alter performance

Comparing joshmkennedy:fix-rewrite-base-path-url (b55b5f8) with main (c5755e1)

Summary

✅ 6 untouched benchmarks

Verified

This commit was signed with the committer’s verified signature. The key has expired.
@ematipico
Copy link
Member

Thank you @joshmkennedy , I've seen that it's not the first contribution you provide to fix some bugs. If you're not aware of it, you can close bugs automatically by using specific messages from your PR description: https://github.com/gitbucket/gitbucket/wiki/How-to-Close-Reference-issues-and-pull-request

Can you update you PR to reflect that? So we won't forget to close the issue next time you provide a fix :)

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From your PR, it seems that we are fixing two bugs. If so, we can provide two changesets, where we thoroughly explain what was the bug. Plus, the changeset you provided isn't very descriptive at the moment. For example url should be Astro.url and ctx.url.

Let's provide a good changelog for our users :)

@joshmkennedy
Copy link
Contributor Author

What should the expected behaviour be when rewriting? Should Astro.rewrite('/path') 404 if trailingSlash is set to always?

The current behaviour is:
Astro.rewrite('/base/path') = 200
Astro.rewrite('/path') = 404

I think it should probably 404, but that might be a breaking change.

Here is an example of what I'm talking about.
https://stackblitz.com/edit/withastro-astro-2tf4syou?file=astro.config.mjs

@ematipico ematipico merged commit 32fafeb into withastro:main Feb 20, 2025
4 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Feb 20, 2025
hkbertoson pushed a commit to hkbertoson/astro that referenced this pull request Feb 21, 2025
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Astro.rewrite does not respect the base path in configuration
3 participants