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(vercel): clear artifacts from redirects #9287

Merged
merged 7 commits into from
Dec 8, 2023
Merged

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Dec 4, 2023

Changes

Testing

Adjusted pre-existing tests

Docs

Does not affect usage

Copy link

changeset-bot bot commented Dec 4, 2023

🦋 Changeset detected

Latest commit: 149121f

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 pkg: integration Related to any renderer integration (scope) pr: docs A PR that includes documentation for review labels Dec 4, 2023
@lilnasy lilnasy marked this pull request as ready for review December 4, 2023 16:24
@matthewp
Copy link
Contributor

matthewp commented Dec 4, 2023

Hm, I'm not sure if we support external intentionally, let me check.

@matthewp
Copy link
Contributor

matthewp commented Dec 4, 2023

Yeah, it was an explicit non-goal of the RFC: https://github.com/withastro/roadmap/blob/main/proposals/0041-redirects.md#non-goals

I wonder how many people are hitting this. I wouldn't mind revisiting this decision, but to do so in a more formal way, as redirects have a bit of complexity to them that I wouldn't want to just enable external in a one-off way.

I'm surprised I didn't already do this, but would it make sense to check if the to is an http link in Astro core and throw/warn on that?

@lilnasy
Copy link
Contributor Author

lilnasy commented Dec 4, 2023

Yeah, an error seems the way to go.

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Dec 4, 2023
destination = to.destination
}
if (destination.startsWith("http")) {
return logger.error('redirects', `Redirecting to an external URLs is not supported: ${from} -> ${to}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

This comment was marked as resolved.

@lilnasy
Copy link
Contributor Author

lilnasy commented Dec 4, 2023

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.

I'm not sure about the changes in redirects.ts, but the others look good to me

@lilnasy
Copy link
Contributor Author

lilnasy commented Dec 6, 2023

The changes in redirects.ts are the ones fixing the issue.

@lilnasy
Copy link
Contributor Author

lilnasy commented Dec 6, 2023

Since we already have VT tests using external redirects, I am switching the "warn and ignore" to a "warn".

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

I'm happy with these changes! Would love @matthewp to confirm as well.

else {
destination = to.destination
}
if (destination.startsWith("http")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is 'httpfoobar' a valid pathname destination? Do we enforce that the pathname starts with /? I guess not since this gets here. So should we be checking for http(s)://?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, we don't validate the paths much.

@@ -27,6 +28,15 @@ describe('Astro.redirect', () => {
expect(response.headers.get('location')).to.equal('/login');
});

// ref: https://github.com/withastro/astro/pull/9287
it.skip('Ignores external redirect', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be unskipped with this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because of the vt test which tests for the opposite.

@lilnasy lilnasy merged commit 1e342e3 into withastro:main Dec 8, 2023
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Dec 8, 2023
@lilnasy lilnasy deleted the fix/9259 branch December 8, 2023 16:36
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) pkg: integration Related to any renderer integration (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirects not working (vercel static)
4 participants