Thanks to visit codestin.com
Credit goes to github.com

Skip to content

handleTrailingSlashRedirect throws when the path is exactly // #873

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

Closed
lujjjh opened this issue May 22, 2025 · 2 comments
Closed

handleTrailingSlashRedirect throws when the path is exactly // #873

lujjjh opened this issue May 22, 2025 · 2 comments

Comments

@lujjjh
Copy link

lujjjh commented May 22, 2025

function handleTrailingSlashRedirect(
event: InternalEvent,
): false | InternalResult {
// When rawPath is `//domain`, `url.host` would be `domain`.
// https://github.com/opennextjs/opennextjs-aws/issues/355
const url = new URL(event.rawPath, "http://localhost");

The call to

new URL(event.rawPath, "http://localhost")

will throw

TypeError: Failed to construct 'URL': Invalid URL

if event.rawPath === "//" and will cause an internal server error.

@sommeeeer
Copy link
Contributor

How did you trigger this from an app? What version of OpenNext are you on? We have this now that should in theory catch that:

const repeatedSlashRedirect = handleRepeatedSlashRedirect(event);
if (repeatedSlashRedirect) return repeatedSlashRedirect;

@lujjjh
Copy link
Author

lujjjh commented May 23, 2025

Oops — I actually ran into this in the logs of a project using @opennextjs/[email protected] and didn’t notice the catch above. I’ve just upgraded to the latest release and can confirm the error no longer occurs. Thanks for the clarification!

@lujjjh lujjjh closed this as completed May 23, 2025
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

No branches or pull requests

2 participants