-
Notifications
You must be signed in to change notification settings - Fork 28k
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
Middleware on localhost redirects to relative URL, even when provided with absolute one #44482
Comments
Can confirm the same issue, though for us the relative url results in a 500 Invalid URL error within next-url. Local node and production edge vercel work without issue but local edge causes this error. For the moment I'm working around the issue by making all redirect urls a full url instead of just the path. Edit: Rereading your post my issue might be different actually, though likely related. |
This comment has been minimized.
This comment has been minimized.
I was trying to read my original post and it's so unclear what it's about. But all in all this is the best summary:
Explanation:
The redirect will be to |
@devklepacki, I have the same issue. Did you find a workaround for this? |
@haozhun actually no. In my case that was not a core or a very dynamic feature. So I just assumed that if on dev I get redirected to |
I worked around this issue by adding |
Can confirm this |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue
https://github.com/devklepacki/reproduction-middleware-redirect
To Reproduce
/signin?domainKey=foobar
http://localhost:3000/signin?domainKey=foobar
Describe the Bug
Next.js middleware redirects to a different URL on localhost (wrong URL) and when deployed to Vercel (works correctly).
I'm doing a simple redirect from
foobar.example.com
toapp.example.com/signin?key=foobar
.When deployed it works as expected. But on localhost final redirection using
NextResponse.redirect()
is relative/auth/signin?key=foobar
, even though the final string is correct:http://localhost:3000/auth/signin?key=foobar
. Example below:It's clearly visible in the Network Headers tab:
Request URL: http://foobar.localhost:3000/
Response location:
/auth/signin?key=foobar
(should behttp://localhost:3000/auth/signin?key=foobar
)So it's clearly middleware's fault to redirect to a relative path. even when absolute is supplied.
Expected Behavior
NextResponse.redirect('http://localhost:3000/foo/bar')
should redirect to the absolute path on localhost, instead of relative path/foo/bar
.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
Vercel
The text was updated successfully, but these errors were encountered: