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

TrailingSlash using rewrite for a fetch call results on infinite loop #280

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

AlbertSabate
Copy link
Contributor

@AlbertSabate AlbertSabate commented Oct 13, 2023

Fixes: #279

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2023

⚠️ No Changeset found

Latest commit: e1875b9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Oct 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
open-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 13, 2023 7:26pm

return {
type: event.type,
statusCode: 308,
headers: {
Location: event.url.replace(/\/$/, ""),
Location: `${headersLocation[0].replace(/\/$/, "")}${headersLocation[1] ? `?${headersLocation[1]}` : ''}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the internalEvent.url in the final return below also split the ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I code-reviewed that part, and it is already handled by handleRewrites fn.
On handleRewrite, we are doing it like this:

const urlQueryString = new URLSearchParams(convertQuery(query)).toString();
const queryString = urlQueryString ? `?${urlQueryString}` : "";
let rewrittenUrl = rawPath;
url: `${rewrittenUrl}${queryString}`,

This should be working as expected because we do not add or remove any slash. On my changes, I've gone for split('?') because there are fewer lines of code. But happy to match the style. I'm not sure if there are some code style guidelines somewhere :D

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be fine, doesn't have to match style.

Copy link
Contributor

@khuezy khuezy left a comment

Choose a reason for hiding this comment

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

Thanks!

@AlbertSabate
Copy link
Contributor Author

Fixed eslint.

@khuezy khuezy merged commit 34c78cb into opennextjs:main Oct 16, 2023
2 checks passed
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.

TrailingSlash using rewrite for a fetch call results on infinite loop
2 participants