-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Recursive redirection occurs when redirecting within the handler #993
Labels
Comments
Thanks for the heads up. That's interesting, it may be a undici thing since I've tested redirects with the pages router back when NTARH used the old node-fetch. I'll investigate and update the docs accordingly. |
My
|
Xunnamius
added a commit
that referenced
this issue
Mar 2, 2024
### [4.0.4](v4.0.3...v4.0.4) (2024-03-02) #### 🪄 Fixes * **src:** allow relative url strings passed via url shorthand for App Router ([01b86b6](01b86b6)) <sup>closes [#1000](https://github.com/Xunnamius/next-test-api-route-handler/issues/1000)</sup> * **src:** prevent recursive redirection with undici/whatwg fetch ([22bb716](22bb716)) <sup>closes [#993](https://github.com/Xunnamius/next-test-api-route-handler/issues/993)</sup> * **src:** replace `AppRouteUserlandModule` with looser type ([502e666](502e666)) <sup>closes [#1006](#1006), [#1005](https://github.com/Xunnamius/next-test-api-route-handler/issues/1005)</sup>
🎉 This issue has been resolved in version 4.0.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note:
This is not a problem caused by this library itself, but rather an issue that can arise when using the library. It is being documented as an issue with the intention of highlighting potential problems that may occur when using the library, and to request its inclusion in the documentation.
Overview of the Issue
When redirecting within an API handler, if you simply call
fetch()
in the test, it recursively triggers redirection. As a result, an error statingredirect count exceeded
occurs.Reproduction Test Code
Executing this code results in the following error:
Solution Approach
By adding
redirect: 'manual'
when callingfetch()
, it prevents automatic redirection to the redirect destination, allowing validation of the response.Updated test code:
See also: https://developer.mozilla.org/en-US/docs/Web/API/fetch#redirect
Expected Fix
To prevent similar issues in the future, it would be beneficial to explicitly mention this in the documentation.
The text was updated successfully, but these errors were encountered: