-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
TypeError: Invalid URL when request: NextRequest is called in app router api route in production #58914
Comments
Theres a bug since 14.0.2 where the |
This nginx workaround resolves the issue, but I don't think it's a proper fix. It may give you more insights into the issue. We shouldn't have to put nginx in front to just fix this. |
The nginx workaround "fixes" the issue because nginx strips the duplicate headers. The PR I linked should fix the underlying issue. |
Any movement on this issue? this still seems to be kicking about still seeing the 'https' added when I am assuming it shouldn't be there:
Confirming:
Originating here: Not a fix just a workaround as working in production so to unblock me, it seems that it should do some further validation on the base.
|
Pardon me but I'm curious why didn't this bugfix (#58824) get backported to 14.1 while 14.2 haven't been out for 3 weeks. We have to stay in 14.0.1 or use the canary version. |
I used |
FYI: We upgraded to the latest canary |
I can confirm that version |
This comment has been minimized.
This comment has been minimized.
I finally tracked down the source of this issue (aside from the multiple next.js/packages/next/src/server/app-render/action-handler.ts Lines 479 to 482 in 3a39a20
It's possible that the origin will be
The code sees that the origin is a string and tries to parse it with
I'm testing with Next v14.2.4, but it looks like this would still be an issue in the canary branch. A workaround is to add this to your middleware: if (req.headers.get("origin") === "null") {
req.headers.delete("origin");
} You'll get this warning, but the action will otherwise work:
|
Rereading through the MDN docs for the 5th time, I just realized that the reason I'm getting
It does make me wonder though, if one of the goals/features of server actions is progressive enhancement, and a simple form post is sent as a non-cors request, then should NextJS/React also send server actions in non-cors mode to match? At least in my case that would have caught this issue way earlier (as soon as we introduced all our security headers). Ignoring At least updating that code so that it doesn't just throw a TypeError (maybe wrapping in a try/catch) would be really helpful for debugging this for other devs with the same issue. |
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/peaceful-smoke-yw6tz9?file=%2Fapp%2F(sitemap)%2Fsitemap%2F%5Bslug%5D%2Froute.ts%3A6%2C1
To Reproduce
Current vs. Expected behavior
Actual result
code should reach
console.log('fn body called')
but instead we get
Expected result
notice that base become
https, https://localhost:3000/sitemap/test
which is incorrect. it should be without https,https://localhost:3000/sitemap/test
Verify canary release
Provide environment information
App is deployed using docker compose Operating System: Platform: linux Arch: x64 Version: #52~20.04.1-Ubuntu SMP Wed Sep 20 16:25:19 UTC 2023 Binaries: Node: 20.9.0 npm: 10.1.0 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 14.0.3 eslint-config-next: 14.0.3 react: 18.2.0 react-dom: 18.2.0 typescript: 4.8.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router
Additional context
In localhost both dev and production build works fine
intentionally call
yields the same error
while
works fine
The text was updated successfully, but these errors were encountered: