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

Rewrites fail when the URL is too long #25481

Closed
sandgraham opened this issue May 26, 2021 · 3 comments · Fixed by #26221
Closed

Rewrites fail when the URL is too long #25481

sandgraham opened this issue May 26, 2021 · 3 comments · Fixed by #26221
Labels
bug Issue was opened via the bug report template.

Comments

@sandgraham
Copy link

sandgraham commented May 26, 2021

What version of Next.js are you using?

10.2.3

What version of Node.js are you using?

14.16.0

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

next export

Describe the Bug

While in development I am trying to use rewrites to proxy a local API server. The rewriting works flawlessly until the length of the URL reaches a certain length- in my case, 990 characters.

Expected Behavior

I'd expect the length of the URL to not impact when a rewrite occurs. Or at least, I'd expect the limit to be large enough to not interfere with reasonable URLs. In my case, I have URLs which need to include certain lengthy tokens (which I do not have control over). If this is intentional, it might be nice to print a warning while in development.

To Reproduce

I was able to reproduce in a fresh project (create-next-app) by adding a next.config.js like so:

module.exports = {
  async rewrites() {
    return [
      {
        source: "/:foo*",
        destination: "https://www.google.com/:foo*", // Can be any URL
      },
    ];
  },
};

Start the dev server and navigate to this URL, which is 256 characters:

http://localhost:3000/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

This should correctly direct you to google (albeit they don't have a page at this URL).

Now navigate to this URL, which is 282 characters:

http://localhost:3000/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

You should instead see a Next.js bad page error. So far as I can tell there is no "rewrite" happening (though I found this kind of difficult to debug).

Note - when creating a reproduction, the length of the URL which caused this issue was different (much shorter) than when I originally ran into the issue (using only localhost). Not sure what that's about...

@sandgraham sandgraham added the bug Issue was opened via the bug report template. label May 26, 2021
@ijjk
Copy link
Member

ijjk commented Jun 17, 2021

Hi, this has been updated in v11.0.1-canary.3 of Next.js, please upgrade and give it a try!

@sandgraham
Copy link
Author

Hi, confirming that after upgrading to v11.0.1-canary.3 the redirects work as expected. Thanks!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants